【发布时间】:2018-04-27 01:14:28
【问题描述】:
【问题讨论】:
-
不,w3.css 中没有 flex 属性(简单的单词搜索会告诉你)
-
如果你发布一个代码 sn-p 可能有另一个可以使用的规则。
【问题讨论】:
既然你有 flexbox 标签,我给你 Flexbox 解决方案:
body {
color: #fff;
}
.parent {
display: flex; /* displays the children inline */
}
.child {
flex: 1; /* children take as much horizontal space as they can */
height: 100px;
}
.A {
background: blue;
}
.B {
background: red;
}
@media screen and (max-width: 568px) { /* adjust to your needs */
.parent {
flex-direction: column; /* stacks the children vertically */
}
.A {
order: 2; /* changes the order, i.e. displays the .A below the .B */
}
}
<div class="parent">
<div class="child A">A</div>
<div class="child B">B</div>
</div>
您也可以使用 Grid:
body {
color: #fff;
}
.parent {
display: grid;
grid-template-columns: repeat(2, 1fr); /* could also use: 1fr 1fr or 50% 50% without the repeat() */
grid-template-rows: repeat(2, minmax(100px, auto)); /* minimum height 100px, maximum height unlimited, adjust to your needs, you can also remove it, not mandatory */
}
.A {
background: blue;
}
.B {
background: red;
}
@media screen and (max-width: 568px) {
.parent {
grid-template-columns: 1fr; /* could also use: 100% */
}
.A {
order: 2;
}
}
<div class="parent">
<div class="A">A</div>
<div class="B">B</div>
</div>
【讨论】: