【发布时间】:2017-05-16 20:12:41
【问题描述】:
我有一个 flexbox 行容器,其中左侧的 flex 项带有一个未指定宽度的图标,第二个 flex 项是一个多行文本块。
问题是,我希望这个文本位于 flexbox 容器的精确中心,并且此时它被第一个 flex 项推到左侧。
居中的一种方法是将文本框的右侧填充到与图标相同的宽度,例如使用margin-right。
或者我可以在文本上设置一个:after 元素以在右侧添加另一个弹性框?最好的方法是什么?
例如
<div style="display: flex; width: 10em; align-items: center; border:1px solid blue; text-align:center">
<a style="flex: none; width:auto">→</a>
<a style="flex:1; /* margin-right: how do I make this the same width as the → box above*/">here <br> is a load of text.<br>I want it to be centered in the div,<br>not shifted to the right</a>
</div>
【问题讨论】:
-
上一个(现有)问题的答案很好且全面
标签: html css flexbox centering