【发布时间】:2016-10-29 14:47:46
【问题描述】:
我有两个子 div 20% 和 80%。最后一个包含嵌套的spans,如果文本不适合同一行,它会按单个单词移动到下一行(默认行为)。
HTML:
<div class="post-short-footer">
<div class="read-more-post"></div>
<div class="post-short-meta-container">
<span class="posted-on"><i class="fa fa-calendar" aria-hidden="true">Some text</i></span>
<span class="cat-links"><i class="fa fa-folder-open-o" aria-hidden="true"></i>Some text</span>
<span class="comments-link"><i class="fa fa-comment-o" aria-hidden="true"></i></span>
</div>
</div>
CSS:
.post-short-footer {
display: table;
width: 100%;
}
.read-more-post {
height: 100%;
display: table-cell;
vertical-align: middle;
width: 20%;
padding: 0.6em 0.6em;
border-radius: 0.3em;
text-align: center;
border: 1px solid #3b9be5;
}
.post-short-meta-container {
display: table-cell;
padding-left: 1em;
width: 80%;
line-height: 100%;
vertical-align: middle;
height: 100%;
}
但是如果 span 中的文本不适合该行,则我需要实现下一个结果,将整个 span 移动到下一行。
我已经试过了:
.post-short-meta-container span {
white-space: nowrap;
}
这不会将文本移动到下一行,而是使第一个 div 更小,以便为文本获得可用空间,这是不可取的行为。
而我想实现:
是否可以仅使用 CSS 获得这样的结果?
【问题讨论】:
标签: html css responsive-design