Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Kerry Russell
Courses Plus Student 2,924 Pointsscaling 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

lordcozycat
11,940 PointsSomething 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?

Kerry Russell
Courses Plus Student 2,924 PointsHi, 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.

lordcozycat
11,940 PointsOn 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.

lordcozycat
11,940 PointsI'd try setting width to whatever you need, then setting height to auto. Hope that works out for you.

Kerry Russell
Courses Plus Student 2,924 PointsThanks Bryan. I'll give that a try :)