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
Yuval Blass
18,134 PointsWhy do I need to give a width in order to center these elements?
Hi, Why do I need to give a width in order to center these elements?
.primary-content,
.secondary-content {
width: 60%;
margin: auto;
}
1 Answer
Yuval Blass
18,134 PointsWhy when I set the width to 100%, Some text not centered?
Savannah Lynn
13,662 PointsThat could be a variety of things. I can't see your full code to know what elements these classes are referencing. If you are trying to center text specifically, try text-align: center. Setting the margin to auto centers elements such as <div> but not always the text.
Savannah Lynn
13,662 PointsSavannah Lynn
13,662 PointsThe browser needs to know how big something is to determine how far to the left or the right it should be from the edge of the browser. Even a size of .000000000001px is still a size the browser can work with. Without a width, the element can't take up any space.