Pixel Border and Percentage width in Proportion

后端 未结 7 1977
误落风尘
误落风尘 2021-02-08 14:30

I think I might already know the answer to this one but I need a sanity check!

Say I have

#gridtest{
width:590px;
}

I could change the

7条回答
  •  無奈伤痛
    2021-02-08 14:45

    The accepted answer is not correct. You actually have 2 options:

    Use the box-sizing property, so all the paddings and borders are considered part of the size:

    .column {
        width: 16%;
        float: left;
        margin: 0 2% 0 2%;
        background: #03a8d2;
        border: 2px solid black;
        padding: 15px;
        font-size: 13px;
    
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    

    Or, use the outline property instead of the border property. You will still have problems with the paddings, but it's easier to add. Example:

    .column {
        width: 16%;
        float: left;
        margin: 0 2% 0 2%;
        background: #03a8d2;
    
        outline: 2px solid black;
    }
    

    Full explanation: http://designshack.net/articles/css/beating-borders-the-bane-of-responsive-layout/

提交回复
热议问题