【发布时间】:2018-04-05 17:38:00
【问题描述】:
我正在尝试格式化一系列警告消息。每条消息都是一个由 3 个 flex 项组成的 flexbox:一个小色环(i 标签),然后是 2 个 p 标签,其文本根据警告的不同而不同。我希望它们都左对齐,第一个 p 和第二个 p 之间的间距一致。
问题是当其中一个 p 元素中有换行符时(当警告标题或描述变得太长时),整个 p 元素的宽度会发生变化并超出文本的右边缘,从而导致左右 p 标签之间的大空白。
.warnings {
width: 600px;
}
.warning {
display: inline-flex;
align-items: baseline;
}
<div class="warnings">
<div class="warning">
<i class="fa fa-circle"></i>
<p class="type">Warning type</p>
<p class="description">Warning description text goes here</p>
</div>
<div class="warning">
<i class="fa fa-circle"></i>
<p class="type">Short Warning type</p>
<p class="description">Warning description text goes here</p>
</div>
<div class="warning">
<i class="fa fa-circle"></i>
<p class="type">Very long warning looks like this</p>
<p class="description">Warning description text goes here</p>
</div>
<div class="warning">
<i class="fa fa-circle"></i>
<p class="type">Warning type</p>
<p class="description">Warning description text goes here and on and on and on and on and on and on</p>
</div>
</div>
【问题讨论】:
-
你试过
white-space: nowrap吗? -
查看此代码笔codepen.io/anon/pen/XExdwo。
-
我确实希望文本能够换行。只是当它换行时,我希望项目的边缘正好靠在文本的边缘。感谢您的回复!
-
哦,那很简单,看我的回答:)
标签: html css flexbox word-wrap