html - 使用 Flexbox 的绝对位置垂直导航
问题描述
我想做一个垂直导航,说是 50px,然后我想有一个弹性区域,里面有我的页眉、主要内容区域和页脚。
现在,当我使用 absolute 时,flexbox 容器会被覆盖为绝对,它在做自己的事情。我想知道我是否可以告诉我的 flex 容器从左侧开始 50px,这样我就不必担心图标会被它吞没。
我是否也必须使 flex 容器成为绝对容器?
解决方案
您不需要任何定位或边距,只需使用附加flex
包装使其自然:
body {margin: 0}
.outerFlex {
display: flex; /* displays flex-items (children) inline */
height: 100vh; /* 100% of the viewport height */
}
nav {
flex-basis: 50px; /* initial width */
background: lightblue;
}
.innerFlex {
flex: 1; /* takes the remaining width */
display: flex;
flex-direction: column; /* stacks flex-items vertically */
background: lightgreen;
}
main {
flex: 1; /* takes the remaining height */
}
<div class="outerFlex">
<nav>Nav</nav>
<div class="innerFlex">
<header>Header</header>
<main>Main</main>
<footer>Footer</footer>
</div>
</div>
推荐阅读
- azure - 防止 Azure 中的 HTTP 主机标头攻击
- ios - 如何在 podfile 中指定 CocoaPods 存储库分支
- python - 两个非常相似的正则表达式,其他找不到匹配
- notepad++ - 如何在记事本++中搜索和替换匹配的命中
- rest - Autodesk Forge,.Net API POST 方法不返回新对象 ID
- java - 使用 Microsoft graph Java Sdk 创建发布请求以将用户添加到组
- java - 如何减少 Spring Boot 控制器中的重复代码
- docker - MDNS 从 Kubernetes 内广播?
- javascript - Javascript工具提示没有随着鼠标移动而移动
- node.js - 同一组件中的方法 - 自动更新