目前我的“flex”项目看起来像这样(垂直对齐:顶部)......
_____________________________________
1
_____________________________________
2
_____________________________________
3
_____________________________________
4
_____________________________________
我的目标是使它们看起来像这样(垂直对齐:中间)......
_____________________________________
1
_____________________________________
2
_____________________________________
3
_____________________________________
4
_____________________________________
我的要求:
-
弹性容器必须保持100%的高度
-
弹性项目必须保持25%的高度(等于100%,无论如何这是默认值) .
-
弹性项目必须垂直居中 .
-
这必须具有响应性并且足够智能以保持每个设备的中间位置(因此没有行高/填充)
http://jsfiddle.net/oneeezy/p4XtA/
HTML
<!-- Flex Box -->
<section>
<!-- Flex Items -->
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</section>
CSS
/* Flex Box */
section { padding: 1em; background: black; display: flex; flex-flow: column; height: 100%; justify-content: space-around; }
/* Flex Items */
div { border-top: 1px solid #ccc; background: #f2f2f2; height: 25%; }
div:first-child { border-top: 1px solid transparent; }
div:hover { background: white; }
4 回答
也许我误解了,但你不能这样做:
HTML (Slim)
CSS
这是Codepen
要垂直对齐flexbox子项的内容,您需要应用其他一些技巧 .
我相信那里会有内容,包含在标签中,然后你可以再次使用
flex
并在margin:auto;
中设置子项 DEMOCSS更新:
HTML结构:
Maybe a fallback 与
display:table
,可以有用: DEMO 2你的问题与所谓的flex-box并没有关系,实际上你要对齐的是 content of the div (而不是
div
),所以只需使用一些技巧来正确对齐它 . 这是一个技巧:演示 .
这是解决问题的方法:
HTML
CSS