Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (40.7k points)

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 width: 100%; causes the input to be 100% + 20px how can I get around this?

Example

1 Answer

0 votes
by (20.3k points)

For box-sizing: border-box is a quick, easy way to fix it:

The code given below will work in all modern browsers, and IE8+.

.content {

    width: 100%;

    box-sizing: border-box;

}

The browser prefixed versions (-webkit-box-sizing, etc.) are not needed in modern browsers.

Have a look at this demo: http://jsfiddle.net/thirtydot/QkmSk/301/

Related questions

0 votes
1 answer
asked Sep 2, 2019 in Web Technology by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...