Set div outerwidth using css

后端 未结 5 689
名媛妹妹
名媛妹妹 2021-01-02 00:48

I wonder if there is way to set outerwidth of a div using css to ignore padding and borders.

When I set a div t

5条回答
  •  不思量自难忘°
    2021-01-02 01:38

    you could split the 50% value assigned to the width as this:

    width: 46%;
    
    margin: 0 1%; // 0 top/bottom and 1% each for left and right
    
    padding: 0 1%; // same as above
    

    you can recalculate the percentages to suit your needs, as long as the total is 50% you should be fine.

    I would avoid using js to fix small cosmetic issues as this would not work with js off and would add extra workload to your client's browser - think of mobile and you will see why performance counts!

提交回复
热议问题