How to make an element width: 100% minus padding?

前端 未结 14 1453
庸人自扰
庸人自扰 2020-11-21 07:33

I have an html input.

The input has padding: 5px 10px; I want it to be 100% of the parent div\'s width(which is fluid).

However using widt

14条回答
  •  长发绾君心
    2020-11-21 08:07

    Use css calc()

    Super simple and awesome.

    input {
        width: -moz-calc(100% - 15px);
        width: -webkit-calc(100% - 15px);
        width: calc(100% - 15px);
    }​
    

    As seen here: Div width 100% minus fixed amount of pixels
    By webvitaly (https://stackoverflow.com/users/713523/webvitaly)
    Original source: http://web-profile.com.ua/css/dev/css-width-100prc-minus-100px/

    Just copied this over here, because I almost missed it in the other thread.

提交回复
热议问题