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! While you're at it, check out some resources Treehouse students have shared here.

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

CSS

Section ,header moving out of div element.....

Header and section element are moving outside of div element on doing width:100% and if I releases from width it becomes right.... I don't know why.... Plz help me.....

5 Answers

Is there padding on the left/right of those two elements? It sounds like box-sizing is the culprit. By default, it's set to content-box - so width (when set) would actually be 100% + padding.

If you're not already, you may want to just set everything to border-box -

*,*:before,*:after {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
}

Its the problem of margin... when i do the margin :some pixels and then give the width 100% , it goes out of parent div and when i remove width and give margin it becomes right...

It is not taking margin-right.......

ah ok, this might not be totally right, but I think if you need the width set to 100% you'd have to remove the right/left margin and pad the parent element instead. With width:auto; the margin should work the way you want though.

The problem was with width only .. I was making width:100%, but I had to make it to max-width:100%.

Now it's working fine...