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

Centering a logo

For some reason I can't center a logo at the top of a page. It sits left of center. Html code is this:
<header> <div class="container">
<img src="img/steadfastlogo-sml2.jpg" alt="steadfast logo" class="logo">

and the CSS is this:

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

I know I have a basic error, but can't figure out what!

Thanks.

I would wrap it with a div with text-align:center;

See here: https://jsfiddle.net/1uxfftL4/

Hi That works, thanks very much! Now to figure out why it works, hehheh.

Thanks! Strangely your response doesn't come up with the option for best answer. You might like to respond in such a way as to give the option.

2 Answers

I think this would work also :

.logo {
    margin: 0 auto;
}

If I´m not mistaken, img-tags default to "display: block", So the "text-align"-propert won´t have any space to work with to actually center the image. if you change display to "inline" you should be able to use text-align. Not 100% sure though.

Certainly simpler. Thanks for your advice :).