CSS: Set divs horizontally in 2 rows

前端 未结 4 728
一向
一向 2021-01-14 09:40

Lets say I have

1
2
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 10:18

    I accomplished this with CSS here using this code: It's kind of hackish though.

    I set three of the divs (the last three) to the class 'double'

    .cont .single {
        background: blue;
        color: white;
        width: 100px;
        height: 100px;
        margin: 10px;
        float:left;
        display: inline-block;
    }
    .cont .double {
        background: blue;
        color: white;
        width: 100px;
        height: 100px;
        margin: 10px;
        display:inline-block;
        float:left;
    }
    
    div:nth-child(5) {
        clear:left;
    }
    
    .cont {
        height: 220px;
        background: red;
    }
    

提交回复
热议问题