我有一个div(父),需要垂直扩展它的父(祖父母)div,其高度为30%。在这个父div内是小盒子(儿童),将容纳图片。孩子们排成3排。 我希望有2到3排儿童和#34;取决于"在其父div的高度。如何根据父div的高度删除/添加行? 对不起,我不知道如何形容这一点。
这可以用css完成吗?我试过溢出:隐藏但我宁愿不要切断'浏览器高度降低时的div。 (你必须增加观看区域的高度才能看到我的意思。
如果没有,是否会有一个简单的JavaScript解决方案? 谢谢!
https://jsfiddle.net/lneale/mxggg847/17/
body{
background-color: gray;
height: 100%;
width: 100%;
margin: 0;
}
#wrapper{
width: 1000px;
height: 30%;
position: relative;
top: 0;
margin: 0 auto;
box-sizing: border-box;
padding: 0 4px 4px 0;
background-color: yellow;
}
#wrapper #rightBlock{
width: 165px; /* needs to be fixed width */
height: 100%;
position: absolute;
top: 0;
right: 0;
box-sizing: border-box;
padding: 6px;
background-color: red;
overflow: hidden;
}
#wrapper #rightBlock #rightBlockSearchBar{
width: 100%;
height: 30px;
margin-top: 10px;
background-color: #ccc;
}
#wrapper #rightBlock #rightBlockTitle{
width: 100%;
height: 30px;
margin-top: 10px;
background-color: #ccc;
}
#wrapper #rightBlock #rightBlockPicContainer{
width: 100%;
height: auto;
margin-top: 10px;
background-color: #fff;
overflow: auto;
}
#wrapper #rightBlock #rightBlockPicContainer .rightBlockPics{
width: 38px;
height: 38px;
margin: 4px;
background-color: blue;
float: left;
}
<body>
<div id="wrapper">
<div id="rightBlock">
<div id="rightBlockSearchBar">search bar</div>
<div id="rightBlockTitle">Title here</div>
<div id="rightBlockPicContainer">
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
<div class="rightBlockPics">
</div>
</div>
</div>
</div>
</body>