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 How to Make a Website CSS: Cascading Style Sheets Style the Basic Elements

How do you center items in css using the margin property?

I have

wrapper {

max width: 940px; margin: 0 center; }

here is a link to show you how to post code so it is easy to read on when you post on the forum.

Code block on Treehouse

6 Answers

Here is a simple example on how to center different elements both vertically and horizontally. If you have any trouble understanding it let us know so we can help you out further

In order to center horizontally you need to have set a width which it looks like you have done so. Then using the margin 0 auto will automatically calculate both the left and right margins for you causing it to be centered.

.wrapper{
max-width: 940px;
margin: 0 auto;
}

It is for one of the tests in the How to make a website path. it says select the Id wrapper, set it to a max width of 940 pixels, and then center it on the page using the margin property. here is the code i have

a { text-decoration: none; }

wrapper {

max-width: 940px; margin: 50; }

In that case when selecting an ID on css you need to add a #.

#wrapper{
max-width: 940px;
margin: 0 auto;
}

Even though I have been told twice it is correct it still wont except my answer for the test and I cannot progess any further until I complete the question.

let me look at the question you are asking about. and see what the issue may be sometimes the wording of the question wants you to do something different. let me take a look. give me a few

hmm. Now it worked. I must have missed something. Thanks guys for your help I really appreciate. I am new to all of this and really like how quick people respond around here. It makes for a great experience.

ok great to hear you got it correct but do you understand what you did wrong? sometimes its best you fully understand the basics before moving on. Or a lot of times you just spelled or have the wrong syntax. Good luck let us know if you need more help.

it didnt work because you needed to add to the code. if you had the text-decoration question from before you should have left that code there and created a new css rule for the wrapper id. I'm pretty sure you just changed it for the new question...i did the same and wasted 10 minutes of my life with that mistake. (4mins searching for an answer,3 figuring it out on my own, and 3 more writing this answer

Matte Matt
Matte Matt
2,354 Points

Can you tell me what you did? I have the same problem