Is it possible to stack unlimited divs left or right arbitrarily without a wrapper?

后端 未结 5 1240
情深已故
情深已故 2021-02-13 20:31

I thought this would be (relatively) easy, but from the answers it seems harder than I anticipated.

Perhaps even impossible!

GOAL

I\'d

5条回答
  •  不知归路
    2021-02-13 21:13

    Put all the left side elements inside a separate div. Also the right elements inside a separate div.

    Then make the css styling as i did in below code snippet.
    It works! Hope this is what you need!

    .left {float:left; background: coral; margin-bottom: 5px;}
    .right {float:right; background: mediumaquamarine; margin-bottom: 5px;}
    .left-wrapper{ float:left; width:60%;}
    .right-wrapper{ float:right; width:30%;}
    
    @media (max-width:400px){
        .left, .right, .left-wrapper, .right-wrapper  {
            width:100%;
        }
    }
    @media (min-width:400px){
        .left {
            width: 100%;
        }
        .right {
            width: 100%;
            float: none;
            display: inline-block;
            margin-left: 10%;
        }
    }
    left one
    left two
    left three
    right one
    right two
    right three
    right four
    right five

提交回复
热议问题