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

后端 未结 5 1247
情深已故
情深已故 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:30

    I am adding one more answer here. I don't want to spoil the previous answer. However, with this answer the necessity to wrap the divs is eliminated.

    JSFiddle here

       
    left one
    right one
    left two
    right two
    left three
    right three
    right four
    right five

    Added float:left;clear : left and float:right;clear:right css properties

    .left {float:left; background: coral; margin-bottom: 5px;}
    .right {float:right; background: mediumaquamarine; margin-bottom: 5px;}
    
    @media (max-width:400px){
        .left, .right  {
            width:100%;
        }
    }
    @media (min-width:400px){
        .left {
            float: left;
        clear : left;
        }
        .right {
            float: right;
            display: inline-block;
            margin-left: 10%;
        clear : right;
        }
    }
    

提交回复
热议问题