Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Input at 100% width overlaps div

Tags:

html

css

I am trying to fix a regular input box with padding, border, inside a div with padding. However, I want the input to have its width to be 100% but as you can see, it overlaps. How do I fix this?

CSS

#one {
    background:red;
    width:300px;
    padding:5px;
}
#two {
    width:100%;
    border:3px solid blue;
    padding:4px;
}

HTML

<div id="one"><input type="text" value="Test" id="two" /></div>​
like image 761
test Avatar asked Jun 16 '12 00:06

test


1 Answers

Add box-sizing: border-box to the input styles. Otherwise, the width is 100%, PLUS the border and padding.

like image 99
Niet the Dark Absol Avatar answered Sep 28 '22 11:09

Niet the Dark Absol