我有一个fixed position
容器,我想将其分为两半,
80%
和20%
底部
这样我应该看起来像这样:
注意:它应该在调整窗口大小时自行调整
here是密码笔:
这是我尝试过的事情:
#wrapper {
padding-left: 0;
transition: all 0.5s ease;
height: 100%;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 200px;
height: 80%;
margin-left: -250px;
overflow-y: auto;
background: rgba(0,0,0,0.9);
transition: all 0.5s ease;
border: 3px solid red;
color:white;
}
.stories-preview-wrapper{
height: 20%;
border:3px solid green;
width:210px;
}
<div id="wrapper" class="toggled hidden-xs">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
</ul>
</div>
<div class="stories-preview-wrapper">
<ul class="sidebar-nav">
<li>hello world 2</li>
<li>hello world 2</li>
</ul>
</div>
</div>
答案 0 :(得分:3)
看看:
#wrapper {
padding-left: 0;
transition: all 0.5s ease;
height: 100%;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
top: 0;
left: 0;
width: 210px;
height: calc(80vh - 6px); /* As you give a border of 3px */
overflow-y: auto;
background: rgba(0,0,0,0.9);
transition: all 0.5s ease;
border: 3px solid red;
color:white;
}
.stories-preview-wrapper{
position: fixed;
height: calc(20vh - 6px); /* As you give a border of 3px */
bottom: 0;
left: 0;
border: 3px solid green;
width: 210px;
}
<div id="wrapper" class="toggled hidden-xs">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
</ul>
</div>
<div class="stories-preview-wrapper">
<ul class="sidebar-nav">
<li>hello world 2</li>
<li>hello world 2</li>
</ul>
</div>
</div>
答案 1 :(得分:0)
如果您对其他解决方案感兴趣。看看Grid。
查看更多信息:
.row{
display: grid;
height: 100%;
grid-template-columns: 500px;
grid-template-rows: 80% 20%;
}
#first {
border: 3px solid red;
}
#second {
border: 3px solid green;
}
<div class="row">
<!-- Sidebar -->
<div class="item" id="first">
<ul class="sidebar-nav">
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
<li>hello world</li>
</ul>
</div>
<div class="item" id="second">
<ul class="sidebar-nav">
<li>hello world 2</li>
<li>hello world 2</li>
</ul>
</div>
</div>