我有两个div
:
代码段
<div id="outer">
<div id="div1" style="position:relative;overflow-y:scroll;width:340px;float:left;display:inline-block"></div>
<div id="div2" style="float:left;clear:left;display:inline-block"></div>
</div>
我该怎么做?
答案 0 :(得分:3)
Flexbox以此为生。
.container {
height: 100px;
display: flex;
flex-direction: column;
outline: 1px red solid;
}
.div1 {
flex-grow: 1;
overflow-y: scroll;
width: 340px;
}
.div2 {
border-top: 1px blue solid;
}
&#13;
<div class="container">
<div class="div1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</div>
<div class="div2">I am div 2.</div>
</div>
&#13;
答案 1 :(得分:0)
要激活overflow-y
,即.div1
内容中的滚动条,其中的内容需要overflow
,如下所示
#outer{
width:100%;
height:auto;
}
#outer > .div1{
width:400px;
height:250px;
background:#f2f;
overflow-y:scroll;
}
#outer > .div2{
width:400px;
height:auto;
background:#f22;
}
&#13;
<div id="outer">
<div class="div1">Div1 Demo text Demo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo text Demo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo textDemo text.</div>
<div class="div2">Div2</div>
</div>
&#13;