你可以伪造它;
- 给容器一个固定的高度和一个隐藏的溢出;
- 给文本一个100%的最小宽度和一个内嵌块显示;
如果有之前的东西,文本将被按下,而隐藏:
Running demo
HTML
With squares, Text doesn't show:
<div class="content">
<span>
<div class="box"></div>
<div class="box"></div>
</span>
<div class="content-empty">Text</div>
</div>
Without, it does:
<div class="content">
<span></span>
<div class="content-empty">Text</div>
</div>
CSS
.content {
border: 2px dashed #bbb;
margin-top:20px;
height: 94px; /* new */
overflow: hidden; /* new */
}
.box {
width: 80px;
height: 80px;
border: 2px solid #444;
display: inline-block; /* new */
margin: 5px;
background-color: #eee;
}
.content-empty {
text-align: center;
vertical-align: middle;
line-height: 94px;
font-size: 26pt;
display: inline-block; /* new */
min-width: 100%; /* new */
background: silver;
}
小号alvadorDalì:为了避免伪造你的测试,我访问了你的个人资料,因为你的昵称:D –
@AndreaLigios抱歉,我不是真的达利:-( –