如何用CSS模拟多个标签

Bal*_*áni 6 html javascript css

当我提出一个有趣的解决方案但我没有真正完成时,我花了一些时间在一个问题上.

查看小提琴并尝试擦除<br/>标签.

这个想法也得到了相同的效果(红色div显示),但没有使用这个解决方案相对可怕.

所以这是我的问题:如何<br/>用CSS或最终的Js 模拟标签?

更难一点:你无法触摸包装.

这是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>
Run Code Online (Sandbox Code Playgroud)

这是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%;
}
Run Code Online (Sandbox Code Playgroud)

dfs*_*fsq 2

您可以.box使用绝对位置进行拉伸,因为它是相对于父级的。这样您就可以确保它占用父容器的整个空间。

.wrapper {
    width:300px;
    display:block;
    position:relative;
    overflow:hidden;
    background-color:gray;
}
.widget {
    width:300px;
    height:300px;
    display:block;
    position:relative;
    background-color:graeen;
}
.box {
    background-color:red;
    visibility:visible;
    position: absolute;
    top: 0; bottom: 0;
    left: 0; right: 0;
}
.box-wrap {
    overflow: hidden;
    height: 0;
    padding-bottom: 60%;
}
.box-wrap div {
    max-width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
    <p>Some text and descriptions</p>
    <div class="widget box-wrap">
        <div class="box"></div>
    </div>
    <p>Some more text and description and some more offcourse and a bit more, and just a tiny bit more</p>
</div>
Run Code Online (Sandbox Code Playgroud)