【发布时间】:2019-03-25 08:44:41
【问题描述】:
我找不到让 div 垂直对齐的方法,它会在溢出时换行到第二列...
我有一个固定高度的 div,在里面我有一个动态可变数量的文本,每个文本都包裹在一个固定宽度的 div 中。
我想以垂直对齐方式显示文本。如果没有足够的空间,则应使用第二列。 我尝试使用 float 和 display: inline-block 但元素不在彼此下方。
我觉得有图会更容易理解:
纯 CSS 解决方案将是最好的!
这里是问题的基本 html 代码:
<div class="container" style="height: 70px; background-color: lightblue;">
<div style="width: 100px;">Alsace</div>
<div style="width: 100px;">Bretagne</div>
<div style="width: 100px;">Centre</div>
<div style="width: 100px;">Lorraine</div>
<div style="width: 100px;">Picardie</div>
</div>
Context: on the left of the main div, I have a country map with different county which can be selected, when a county is selected I want to display it's name close to the map.这就是为什么我希望文本最靠近左侧。
【问题讨论】:
标签: html css vertical-alignment