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

Resizing Image Height

I'm using my own images, which are not the same ratio as Nick's. The width of the pics are resized appropriately to fit in the li, but their height causes the li to grow vertically, making the different li uneven vertically.

Is there a way to set the height for the li like we did with the width?

3 Answers

Thank you for your responses! Unfortunately they didn't work (I realize my question was a bit hard to answer given that I didn't provide any example code), but I was able to find a solution after pouring through StackOverFlow.

In order to resize the image, to fit within the li, I did the following:

First, I added a "gallery_pic" class to my gallery images.

<img src="img/RainySunset.jpg" class="gallery_pic" alt"">

Then I wrote a bit of code for the "gallery_pic" class to resize the image.

.gallery_pic {
  object-fit: cover;  /* Scales the image */
  object-position: center;  /* Center the image within the element */
  width: 100%;  /* Fills the li horizontally */
  height: 80%;  /* Fills the li almost all the way vertically, but still leaves room for the caption text below it */
}

Lastly, and MOST IMPORTANTLY, you have to set the height for the li

#gallery li{
    float: left;
    width: 45%;
    height: 300px; /* <--SUPER IMPORTANT! I set mine to 300px but you can set it to pretty much whatever you want */
    margin: 2.5%;
    background-color: #f5f5f5;
    color: #bdc3c7;
}

I think that's everything! Just a side note, Workspaces will highlight object-fit and object-position red. I think this means Workspaces doesn't recognize it? But don't worry about it, the code is valid and the browser knows what to do with it!

Thanks again to everyone who responded and was willing to help me :)

Some code would help us understand the situation better. But Try setting 'min-height' or 'max-height' etc...

max-height: XXXpx; overflow:hidden; Try that.