首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >响应设计以改变div的顺序和位置

响应设计以改变div的顺序和位置
EN

Stack Overflow用户
提问于 2015-08-01 07:35:26
回答 1查看 2.2K关注 0票数 1

这个小提琴演示了我的问题:http://jsfiddle.net/petebere/vbt7mhL5/

对于高达800 in的屏幕宽度,div的顺序应与html结构中的顺序相同。

但是,对于大于800 for的屏幕宽度,我想

  • 绿色div (面板-1)粘在物品的左上角;
  • 红色的div (面板-2)贴在物品的右上边;

如图所示:http://s10.postimg.org/q12rv2ewp/flexbox.jpg

到目前为止,我已经能够使用“display:flex”和“order”属性将绿色和红色div向上移动,但是我不知道如何将绿色div移动到左边,红色div移动到右边。

HTML代码:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
.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;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-08-01 09:32:41

请用你的CSS替换这个CSS,它可以解决你的问题。

此外,我有更新您小提琴演示http://jsfiddle.net/vbt7mhL5/5/

注意:-在设置宽度的item列表中再添加一个类( item )。

代码语言:javascript
复制
.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;*/
    }
}

如果你得到了你的答案,然后接受我的答案,所以有些人很容易得到正确的答案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31759474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档