How to give border to any element using css without adding border-width to the whole width of element?

前端 未结 11 1886
礼貌的吻别
礼貌的吻别 2020-12-02 10:19

How to give border to any element using css without adding border-width to the whole width of element?

Like in Photoshop we can give stroke- Inside , center and out

11条回答
  •  再見小時候
    2020-12-02 10:57

    Check out CSS box-sizing...

    The box-sizing CSS3 property can do this. The border-box value (as opposed to the content-box default) makes the final rendered box the declared width, and any border and padding cut inside the box. You can now safely declare your element to be of 100% width, including pixel-based padding and border, and accomplish your goal perfectly.

    • -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    • -moz-box-sizing: border-box; /* Firefox, other Gecko */
    • box-sizing: border-box; /* Opera/IE 8+ */

    I'd suggest creating a mixin to handle this for you. You can find more information on box-sizing at W3c http://www.w3schools.com/cssref/css3_pr_box-sizing.asp

提交回复
热议问题