Я выполнял туториал здесь: https://scotch.io/tutorials/get-to-know-the-flexbox-grid-in-foundation-6 и пытался растянуть здесь:
https://codepen.io/chrisoncode/pen/wMWEVE
<p class = "text-center">Aligned Stretch (Columns are Equal Height)</p>
<div class = "row align-stretch text-center">
<div class = "columns">space</div>
<div class = "columns">
<p>Look I'm a bunch of words. Spoiler alert for Star Wars: Jar Jar Binks is the new sith lord. He is Darth Darth Binks.</p>
</div>
</div>
body { padding-top:50px; }
.row { border:1px solid #FF556C; margin-bottom:20px; }
.columns { background:#048CB9; color:#FFF; padding:20px; }
.columns:first-child { background:#085A78;vertical-align:bottom }
.columns:last-child { background:#B3BBBB; }
В третьем примере, используя свойство stretch, я пытаюсь заставить текст выровняться по центру по вертикали, и мне не повезло. Кто-нибудь может сказать мне, как это сделать?
Я попытался добавить .columns:first-child {background:#085A78;vertical-align:bottom}, но это не сработало.
HTML:
<p class = "text-center">Aligned Stretch (Columns are Equal Height)</p>
<div class = "row align-stretch text-center">
<div class = "columns">
<div class = "row align-center text-center"><p>space</p></div>
</div>
<div class = "columns">
<p>Look I'm a bunch of words. Spoiler alert for Star Wars: Jar Jar Binks is the new sith lord. He is Darth Darth Binks.</p>
</div>
</div>
CSS:
div.row.align-stretch.text-center .columns {
display: flex;
justify-content: center;
align-items: center;
}
div.row.align-stretch.text-center .columns p {
margin: 0;
}
Дочерние элементы Flex по умолчанию имеют одинаковую высоту, если вы не присвоите значение align-items, отличное от stretch.
Для этого:
<div class = "row align-stretch text-center">
Такой же как:
<div class = "row text-center">
Для вашего примера самый простой способ — использовать .align-middle
, который сделает столбец высотой содержимого внутри и вертикально отцентрирует его по более высокому столбцу в группе.
В противном случае можно сделать саму колонку display: flex;
и добавить align-items: center;
Ваше решение центрирует div, но не растягивает его. Я хотел использовать растяжку, а также вертикально выровнять текст внутри.
Ничего страшного, рад, что помогло.