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
Abacus Bosnia
459 PointsCSS / WIDTH MARGIN
Hello, can you answer me...
Why we need to define width when we want to center something.. Like this..
div{ width:960px; margin:0 auto; }
3 Answers
Joshua O'Connor
6,005 PointsWithout width it wont center. We need to know how wide the webpage is so that we know where we want it centered. Its like trying to find a middle of an object without a width. Once we establish a width, we can establish a center.
Mireille Pasos
35,469 PointsHello,
If you don't define the width of the DIV, it will by default expand to fit the width of its containing element (or parent). Therefore, there would be no use in even trying to center it.
Abacus Bosnia
459 PointsThank you Mireille and Joshua.