Posted in image formatting
2520
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
14
This Month
130
This Year
453

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
The problem with hoarding is you end up living off your reserves. Eventually, you’ll become stale. If you give away everything you have, you are left with nothing. This forces you to look, to be aware, to replenish. . . . Somehow the more you give away, the more comes back to you.
Paul Arden
Random CSS Property

text-decoration-skip-ink

The text-decoration-skip-ink CSS property specifies how overlines and underlines are drawn when they pass over glyph ascenders and descenders.
text-decoration-skip-ink css reference