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
Gabriel E
8,916 PointsHow can I size an image exactly?
Hi, I'm trying to size the height on my image on my webpage exactly, but can I do that in css? Thanks, also could you include some css code?
Gabriel E
8,916 PointsI just want to size each image with css so that they are all exact
2 Answers
Stanley Thijssen
22,831 PointsSelect the image you want with your css selector and give them a height and width:
(your css selector on the image you wnna adjust) {
height: 100px;
width: 100px;
}
Gabriel E
8,916 Pointsalright, thanks!
Erwin Meesters
15,088 PointsThat's not the right way actually. When you have images on your page which differ in height and width, you cannot make them the same size by selecting these images directly and give them a height and width. Your images will look distorted.
There are two way's to solve this:
- Make your images the same size in Photoshop or something and crop them out to 100x100px.
- Put the images in a parent container div and give the container a height and width of 100x100px and your image a max-width of 100%;
.image-container {
height: 100px;
width: 100px;
overflow: hidden;
}
.image-container img {
max-height: 100%;
width: auto;
}
You will loose part of your image, if you don't want that the best way is to crop them the same size with Photoshop. But cropping with Photoshop does essentially the same thing but you have better control over the part that's gets cut out.
Stanley Thijssen
22,831 PointsStanley Thijssen
22,831 PointsDo you mean you want a full page image thats the size of your whole webpage?
Or you just wnna adjust the size of an image with css?