这个小提琴演示了我的问题:http://jsfiddle.net/petebere/vbt7mhL5/
对于最大800px的屏幕宽度,div的顺序应与html结构中的顺序相同。
然而,对于大于800px的屏幕宽度,我想
如此图片所示:http://s10.postimg.org/q12rv2ewp/flexbox.jpg
到目前为止,我已经能够使用'display:flex'结合'order'属性来移动绿色和红色div,但我无法弄清楚如何将绿色div移动到左边和红色div在右边。
HTML代码:
<div class="header">
<div class="menu-top">menu-top</div>
</div>
<div class="content">
<div class="article-1">article-1<br>This will be an article about some interesting topic.</div>
<div class="article-2">article-2<br>This will be an article about some interesting topic.</div>
<div class="panel-1">panel-1<br>This should be on left for screen width > 800px.<br>It should 'stick' to the side of the articles.</div>
<div class="article-3">article-3<br>This will be an article about some interesting topic.</div>
<div class="panel-2">panel-2<br>This should be on right for screen width > 800px.<br>It should 'stick' to side of the articles.</div>
<div class="article-4">article-4<br>This will be an article about some interesting topic.</div>
<div class="article-5">article-5<br>This will be an article about some interesting topic.</div>
</div>
<div class="footer">
<div class="menu-bottom">menu-bottom</div>
</div>
CSS:
.header, .footer {
width: 100%;
}
.menu-top, .menu-bottom {
background-color: LightGray;
text-align: center;
}
.content {
display: flex;
flex-direction: column;
text-align: center;
}
.panel-1 {
background-color: ForestGreen;
text-align: center;
}
.panel-2 {
background-color: crimson;
text-align: center;
}
.article-1 {
background-color: LightSteelBlue;
}
.article-2 {
background-color: PaleTurquoise;
}
.article-3 {
background-color: LightBlue;
}
.article-4 {
background-color: LightCyan;
}
.article-5 {
background-color: PowderBlue;
}
@media screen and (min-width:801px) {
.content {
align-items: center;
}
}
@media screen and (min-width:801px) {
.article-1, .article-2, .article-3, .article-4, .article-5 {
width: 400px;
}
}
@media screen and (min-width:801px) {
.panel-1 {
order: -3;
}
}
@media screen and (min-width:801px) {
.panel-2 {
order: -1;
}
}
@media screen and (min-width:801px) {
.article-1 {
order: -2;
}
}
答案 0 :(得分:1)
请用您的CSS替换此CSS可以解决您的问题。
我也更新了你的演示http://jsfiddle.net/vbt7mhL5/5/。
注意: - 在项列表中再添加一个类(项)以设置宽度。
.header, .footer {
width: 100%;
}
.menu-top, .menu-bottom {
background-color: LightGray;
text-align: center;
}
.content {
display: flex;
flex-direction: column;
text-align: center;
}
.panel-1 {
background-color: ForestGreen;
text-align: center;
}
.panel-2 {
background-color: crimson;
text-align: center;
}
.article-1 {
background-color: LightSteelBlue;
}
.article-2 {
background-color: PaleTurquoise;
}
.article-3 {
background-color: LightBlue;
}
.article-4 {
background-color: LightCyan;
}
.article-5 {
background-color: PowderBlue;
}
@media screen and (min-width:801px) {
.content {
align-items: center;
}
.item{
width: 33.33%
}
/*.article-1, .article-2, .article-3, .article-4, .article-5 {
width: 400px;
}*/
.panel-1 {
order: -3;
position: absolute;
top: 27px;
left: 0;
}
.panel-2 {
align-self: flex-end;
order: -1;
position: absolute;
right: 3px;
top: 27px;
}
.article-1 {
/*order: -2;*/
}
}
如果你得到答案然后接受我的答案,那么有人可以轻松得到正确答案。