【发布时间】:2015-10-23 22:02:05
【问题描述】:
这个小提琴演示了我的问题:http://jsfiddle.net/petebere/vbt7mhL5/
对于高达 800 像素的屏幕宽度,div 的顺序应与 html 结构中的顺序相同。
但是对于大于 800px 的屏幕宽度我想要
- 绿色 div(panel-1)贴在文章的左上角;
- 红色 div (panel-2) 贴在文章的右上角;
如图所示: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;
}
}
【问题讨论】:
-
你可以使用引导程序吗?
-
我可能可以。虽然我还没有使用它,所以这意味着对现有 html 和 css 结构的更深刻的改变。所以目前我正试图弄清楚我们是否可以使用干净的 html 和 css 来实现所需的解决方案。
-
可以对 HTML 进行多少调整?理想情况下(和语义上)文章应该在一个单独的包装器中。然后它变得容易容易。
-
HTML 可以修改 - 没问题。我们只是不知道如何组织各个 div 和包装器以实现所需的布局。
标签: html css responsive-design flexbox