Compact arrangement of DIVs in two directions

后端 未结 5 2324
陌清茗
陌清茗 2020-12-16 22:50

It is easy to arrange DIVs horizontally with float. For example:

5条回答
  •  忘掉有多难
    2020-12-16 23:01

    Or if you are no big fan of absolute positioning (like I am) try this:

    With the corresponding CSS:

    #red {
        width: 180px;
        height: 200px;
        background-color: Red;
    }
    
    #yellow {
        width: 200px;
        height: 100px;
        background-color: Yellow;
    }
    
    #blue {
        width: 150px;
        height: 60px;
        background-color: Blue;
    }
    
    #green {
        float: left;
        width: 140px;
        height: 240px;
        background-color: Green;
    }
    
    #purple {
        width: 130px;
        height: 160px;
        background-color: Purple;
    }
    

    Here's a small demo.

提交回复
热议问题