Piotr Berebecki
Piotr Berebecki

Reputation: 7468

Responsive design to change the order and position of divs

This fiddle demonstrates my problem: http://jsfiddle.net/petebere/vbt7mhL5/

For screen width up to 800px the order of the divs should be as in the html structure.

However for screen width larger than 800px I would like

as shown on this image: http://s10.postimg.org/q12rv2ewp/flexbox.jpg

So far I have been able to use the 'display: flex' combined with 'order' property to move green and red div up, but I can't figure out how to move the green div to the left and red div to the right.

The HTML code:

<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;
    }
}

Upvotes: 1

Views: 2395

Answers (1)

Dipesh Shihora
Dipesh Shihora

Reputation: 424

Please replace this CSS with your CSS It can be solve your issue.

also I have update you fiddle demo http://jsfiddle.net/vbt7mhL5/5/ .

Note:- add one more class (item) in your item list for set the width.

.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;*/
    }
}

If you got your answer then accept my answer,so some one get easily correct answer.

Upvotes: 1

Related Questions