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

Mona Jalal
Mona Jalal
4,302 Points

vertical align = middle doesn't work for image

How can I vertically align the image in the middle? The following doesn't work:

        <img  class = "m-y-1" src="./assets/img/sharif.png" alt="" style="height:100px; width:100px; display: inline-block; vertical-align: middle;"> </img>

1 Answer

Kristopher Van Sant
PLUS
Kristopher Van Sant
Courses Plus Student 18,830 Points

Hi Mona! I think we'll need a little more code and info to understand what's going wrong here, and what exactly you're try to do. You mentioned you want to align the image in the middle, but in the middle of what exactly? Are you trying to align the image with other elements on the same line? Or are you trying to vertically-center the image? If you are trying to vertically-center you might want to use flexbox or something else since the vertical-align property isn't really meant for that.

Here's a few resources in the mean time that help explain vertical-align a bit more. http://phrogz.net/css/vertical-align/ https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align https://css-tricks.com/what-is-vertical-align/ https://css-tricks.com/almanac/properties/v/vertical-align/