[英]Width of div taking all remaining width
我想在左侧菜单的右边放一个顶栏。 我把width: 100%
我的#top_bar
width: 100%
,但是那么大。 我希望我的顶栏只占用屏幕的剩余空间。
HTML:
<body>
<div id="menu_left"></div>
<div id="top_bar"></div>
</body>
CSS:
#menu_left {
background-color: #354052;
position: fixed;
height: 100%;
float: left;
width: 200px;
}
#top_bar {
border-bottom: 1px solid #EFF0F3;
position: absolute;
background-color: white;
left: 200px;
height: 70px;
width: 100%;
}
结果:
#top_bar {
border-bottom: 1px solid #EFF0F3;
position: absolute;
background-color: white;
top: 0px;
left: 200px;
right: 0px;
height: 70px;
}
您可以使用左边距为大div
CSS:
#menu_left {
background-color: #354052;
position: fixed;
height: 100%;
float: left;
width: 200px;
}
#top_bar {
border-bottom: 1px solid #EFF0F3;
background-color: red;
margin-left: 200px;
height: 70px;
}
HTML:
<body>
<div id="menu_left"></div>
<div id="top_bar"></div>
</body>
工作演示
只需将此添加到您的CSS:
body {
margin: 0;
width: 100%;
overflow: hidden;
}
也许这个 ? 您只能更改width: 100%
到right: 0
。 float: left
是不必要的。
html, body { width: 100%; height: 100%; margin: 0; } #menu_left { background-color: #354052; position: fixed; height: 100%; width: 200px; } #top_bar { border-bottom: 1px solid #EFF0F3; position: absolute; background-color: white; left: 200px; right: 0; height: 70px; }
<div id="menu_left"></div> <div id="top_bar"></div>
尝试在元素周围使用100%宽度的容器。
<div class="container">
<div id="menu_left">
</div>
<div id="top_bar">
NAVIGATION
</div>
</div>
看到我刚刚创建的这支笔: http : //codepen.io/anon/pen/MwodLx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.