[英]extending width of floated div
您應該使用flexbox。 這是您的筆編輯的
CSS:
#container{
background: rgba(0,0,0,.1);
width:100%;
height:auto;
position: relative;
overflow: hidden;
display: flex;
}
@media screen and (max-width: 800px) {
#container{
flex-direction: column;
}
}
.wrap1{
background: rgba(100,10,10,.2);
flex-grow: 1;
}
.wrap2{
background: rgba(10,100,10,.2);
height: 100px;
flex-grow: 1;
}
您可以使用Bootstrap CSS進行此操作。 您將要創建一個流體容器,然后創建兩個內部div。 內部div將具有col-md-6類,對於大屏幕它將為50%,對於xtra小屏幕將為col-xs-12。 這將隨瀏覽器自動調整大小。
<div class="container-fluid">
<div class="col-md-6 col-xs-12">Div 1</div>
<div class="col-md-6 col-xs-12">Div 2</div>
</div>
flexbox
解決方案。不需要媒體查詢。
#container { background: rgba(0, 0, 0, .1); display: flex; flex-wrap: wrap; } [class^="wrap"] { flex-grow: 1; flex-shrink: none; } .wrap1 { background: rgba(100, 10, 10, .2); } .wrap2 { background: rgba(10, 100, 10, .2); height: 100px; } #one { width: 200px; height: 200px; background: rgba(100, 100, 0, .1); margin: 0 auto; } #two { width: 300px; height: 100px; background: rgba(100, 100, 0, .1); margin: 0 auto }
<div id="container"> <div class="wrap1"> <div id="one"> </div> </div> <div class="wrap2"> <div id="two"> </div> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.