我在思考一个问题时想到了一个有趣的但不是最终解决方案。
请查看Fiddle并尝试删除<br/>
标签。
这个想法是获得相同的效果(显示红色div),但不使用这个相对可怕的解决方案。
所以我的问题是:如何使用CSS或JS模拟<br/>
标签?
只有一个更大的难度:您不能触摸包装器。
以下是HTML代码:
<div class="wrapper">
<p>Some text and descriptions</p>
<div class="widget box-wrap">
<div class="box"><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
</div>
<p>Some more text and description and some more offcourse and a bit more, and just a tiny bit more</p>
</div>
这里是CSS代码:
.wrapper {
width:300px;
display:block;
position:relative;
overflow:hidden;
background-color:gray;
}
.widget {
width:300px;
height:300px;
display:block;
position:relative;
background-color:green;
}
.box {
background-color:red;
visibility:visible;
}
.box-wrap {
overflow: hidden;
height: 0;
padding-bottom: 60%;
}
.box-wrap div {
max-width: 100%;
}