auto space between horizontal divs in CSS

后端 未结 4 481
北海茫月
北海茫月 2021-02-08 03:36

I\'ve searched a lot but I was not lucky to find a solution to what I am after!

Here is the issue: I\'ve created a master div (width 100%) and within it there are severa

4条回答
  •  有刺的猬
    2021-02-08 04:21

    Here is JSFiddle

    Assume that you have 100% and you have 4 pieces. 4 pieces means you have 3 margin-left block so, when you make your div 22*4=88 then 100-88=12 then 12/3=4 then your margin-left must be:4

    div.box_frame{
        float: left;
        background-color: #eee; /* standard background color */
        border: 1px solid #898989; 
        border-radius: 11px;
        padding: 2px;
        margin-left:4%;
        text-align: center;
        /* change border to be inside the box */
        box-sizing:border-box;
        -moz-box-sizing:border-box;
        -webkit-box-sizing:border-box;
    }
    div.box_frame:first-child{
        margin-left: 0;
    }
    div.box_frame#_15{ /* width 15% */
        width: 22%;
    }
    

    So if you use less variables then you can use this solution without depending on number of div blocks

提交回复
热议问题