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 can I center this element

<iframe width="560" height="315" src="https://www.youtube.com/embed/MyqtIdSSlS0" frameborder="0" allowfullscreen></iframe>

Steven Parker
Steven Parker
243,656 Points

It would help if you posted your code, or even better, a snapshot of your workspace.

2 Answers

Steven Parker
Steven Parker
243,656 Points

Without seeing the code, I can only give you some generic suggestions.

For a block element, give it a specific size and auto margins, and for an inline element, give it the text-align property with the value center.

.center-block {
    width: 100px;  /* set this to the size of your content */
    margin: auto;
}

.center-text {
    text-align: center;
}

you can center element like this

.center-element { display:block; margin: 0 auto; width:100px; }