Change order of floated divs with CSS

后端 未结 4 515
孤城傲影
孤城傲影 2020-12-16 15:07

JSFIDDLE

I want to change the order of floated divs at a certain pixel size.

At default state they both have 50% width and they are next to

4条回答
  •  爱一瞬间的悲伤
    2020-12-16 15:36

    So far, there are no mobile first answers, which is fewer lines of css, and other benefits. This does touch the html, so it's not the OP's question, for a CSS only approach it's the Flexbox answer from two other peeps, which I have voted up.

    DEMO: http://jsfiddle.net/mhrf6d4n/

    HTML, put in source order of the smallest viewport first:

    CSS (put the shared, global to all viewports outside of media queries, combine shared selectors, then after put the min-width and put your floats in there)

    .yellow, .red {
        background: yellow;
        height: 300px;
    }
    .red {
        background: red;
    }
    
    @media screen and (min-width:600px) {
        .yellow, .red {
            float:left;
            width:50%;
        }
    }
    

提交回复
热议问题