Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
glenn romaniuk32,240 Points
input text extends outside div
i have a div and im setting the width of the input text to 100% and it extends outside its container. Why?
<div style="background: tomato; margin: auto; width:90%;height:100px;">
<label class="" for="username" style="display:block;">User Id:</label> <input type="text" style="width:100%;margin:0;"> </div>
Frantisek Musil5,403 Points
The reason is, that borders don't count to the width of the element so your input will take 100% height + border size (2px in each side by default). To avoid this, you can use CSS3 property box-sizing: border-box; This will make the border part ot the input element, so it will souldn't extend anymore.
However, I recommend you not using inline styles, but having all CSS in external file (in case this wasn't just for illustration purposes)
Let me know if it has helped you. Frank