input text box width same as parent

前端 未结 3 941
走了就别回头了
走了就别回头了 2021-01-18 05:01

How can I have a textbox that inherits the width of it\'s container?

For example I have a div that has a textbox inside it.

3条回答
  •  礼貌的吻别
    2021-01-18 05:41

    You should use box-sizing:border-box together with width:100%. This way input will fit 100% of container's width but will not overflow it because of added input's padding:

    #content input
    {
        width:100%;
        box-sizing:border-box;
        -moz-box-sizing:border-box;
    }
    

    Live demo: http://jsfiddle.net/745Mt/1/

    More information about box-sizing CSS property with examples: http://css-tricks.com/box-sizing/

提交回复
热议问题