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

General Discussion

scaling images in height, not width

Hi, is it possible to make an image scale in height, but cut off in width from the right?

Not sure how this would be done, css? or even if it's possible? :)

4 Answers

Something like this?

img {
    max-height: 500px;
    width: 200px;

I would say it's for sure possible, but I'm not sure what you mean by cut it off from the right. Could you explain?

Hi, thanks for the reply Bryan :)

Similar to Lee McIntyre's site. I can see he's using a background image and when you scale the site down to mobile his pic reduces in height and then starts to cut off from the side, rather than it getting so small you can no longer see him.


On that site, the image is set like so:

img {
    background-size: cover;
    width: 100%;

That sets it to cover (This keyword specifies that the background image should be scaled to be as small as possible while ensuring both its dimensions are greater than or equal to the corresponding dimensions of the background positioning area.), and width to 100%. That of course means that the image will fit to the size of it's container, which is set to scale with the page.

I'd try setting width to whatever you need, then setting height to auto. Hope that works out for you.

Thanks Bryan. I'll give that a try :)