Posted in image formatting
2537
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
27
This Month
147
This Year
470

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
A.A. Milne’s Winnie-the-Pooh: “If you live to be a hundred, I want to live to be a hundred minus one day so I never have to live without you.”
A.A. Milne
Random CSS Property

min-width

The min-width CSS property sets the minimum width of an element. It prevents the used value of the width property from becoming smaller than the value specified for min-width.
min-width css reference