【发布时间】:2016-11-21 10:21:38
【问题描述】:
所以我从 stackoverflow 得到了这个三列布局示例,但我正在尝试使用 flexbox 获取列和行。
我的最终目标是有一个三栏布局(左边是图片,右边两栏是文字)。
但是,我需要将所有内容对齐(文本和图像在同一轴上对齐)。
但我的问题是,当我尝试使用 margin-bottom 将列中的元素隔开时,只有第一列文本有效(而不是图像列),我不知道为什么。
我希望左列 margin-bottom 也能正常工作。但即使我为所有列添加margin-bottom,也只有带有 div 的列有效。
我也应该把我的图片放在 div 中吗?
这是我面临的问题的图片:
* {
margin: 0;
}
html,
body {
height: 100%;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
width: 80%;
height: 100%;
margin: 0 auto;
}
.left {
display: flex;
flex-flow: column wrap;
align-items: flex-start;
justify-content: flex-start;
order: 1;
background: red;
flex-basis: 100%;
height: 100%;
}
.middle {
display: flex;
flex-flow: column wrap;
align-content: flex-start;
justify-content: flex-start;
order: 3;
background: green;
flex-basis: 100%;
height: 100%;
}
.right {
order: 2;
background: yellow;
flex-basis: 100%;
height: 100%;
}
.box {
display: flex;
flex-flow: column wrap;
align-items: flex-start;
justify-content: flex-start;
height: 50px;
width: 50px;
}
@media screen and (min-width: 600px) {
.container {
flex-wrap: nowrap;
}
.left {
flex-basis: 1;
order: 1;
}
.middle {
flex-basis: 1;
order: 2;
}
.right {
flex-basis: 1;
order: 3;
}
}
.left,
.right,
.middle * {
margin-bottom: 25%;
}
<div class="container">
<div class="left">
<img src="cat1.jpeg" alt="cat">
<img src="cat1.jpeg" alt="cat">
</div>
<div class="middle">
<div class="box">`
<p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
</div>
<div class="box">`
<p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
</div>
</div>
<div class="right"></div>
</div>
【问题讨论】:
-
其实你是在尝试显示表格信息,所以使用表格会比使用弹性框更合适。