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

horizontal aligning

Hi,

I am trying to center some things horizontally, in particular an image. Here is the current outcome: http://codepen.io/1marty4sale/full/vICFb

<div class="box" id="download-voobly">
    <h5>Download Voobly</h5>
            <img src="http://www.choiceas.com/box1.svg" id="download-img" alt="Download Icon">
            <p><a href="#" class="button-medium">Download</a></p>
    <a href="#">Version History</a>
</div>
#download-voobly {
      padding: 20px;
      text-align: middle;
  border: solid;
  margin: 0 40%;
}

#download-img {
    max-width: 70%;
    margin-left:auto;
    margin-right:auto;
}

It was my understanding that the margin-auto made things centered, so what am I doing wrong?

Thanks, Marty

2 Answers

Change text-align: middle to text-align: center

This will center all your elements. Is that what you wanted?

You can remove the margin properties on your img.

I think margin auto only works on block level elements. img is an inline element by default.

Thank you! Feel silly for trying for as long as I did without working it out now but glad I understand why it wasn't working so I really appreciate your help.

First of all please set display: inline-block on p and img:

#download-voobly img, #download-voobly p{ display: inline-block}

Then set up #download-voobly with text-align: center:

#download-voobly{ text-align: center}