Posted in image formatting
2538
4:32 am, November 9, 2022
 

can you set all image heights to match with css no stretching

Short Answer: Yes with object-fit: cover; on the css of the image properties. 

object-fit: cover;

You might also need: 

object-position: right bottom;

..

HTML

<h3>Images that are all over the place</h3>
<p>images that do not look nice and formatted in a grid.</p>
<div class="image-heights">
	<img src="https://picsum.photos/100/300">
  	<img src="https://picsum.photos/300/200">
  	<img src="https://picsum.photos/100/220">
	<img src="https://picsum.photos/100/300">
  	<img src="https://picsum.photos/300/200">
  	<img src="https://picsum.photos/100/220">
</div>
<hr>
<h3>Add object fit and apply a height and width</h3>
<p>add a class to these images and they all line up nicely with no stretching of the images</p>
<div class="nice-heights">
	<img src="https://picsum.photos/100/300">
  	<img src="https://picsum.photos/300/200">
  	<img src="https://picsum.photos/100/220">
	<img src="https://picsum.photos/100/300">
  	<img src="https://picsum.photos/300/200">
  	<img src="https://picsum.photos/100/220">
</div>

CSS

.nice-heights img {
	height:200px;
  	width:200px;
  	object-fit: cover;
  	object-position: left top;
  	margin-bottom:5px;
  	margin-right:5px;
}

Images that are all over the place

images that do not look nice and formatted in a grid.


Add object fit and apply a height and width

add a class to these images and they all line up nicely with no stretching of the images

View Statistics
This Week
28
This Month
148
This Year
471

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


minecraft
Random CSS Property

translate

The translate CSS property allows you to specify translation transforms individually and independently of the transform property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the transform value.
translate css reference