I'm using Clip-path to cut around an image to make it a smaller rectangle than before. However the box I'm putting it in is treating it like the rest of the image is still there. Is there a way to get rid of the excess portion of the image and just use the clip-path portion of the image?
.image {
width: 20%;
height: 20%;
clip-path: inset(70% 22% 11% 22%);
box-shadow: inset 0 0 10px #000000;
}
I'm trying to fit only that portion of the image somewhere. Outside of forcing it using negative/overlapping the cutout portion, is there another way to go about it?
.clipimage {
width: 20%;
height: 20%;
clip-path: inset(70% 22% 11% 22%);
box-shadow: inset 0 0 10px #000000;
}
.noimage {
width: 20%;
height: 20%;
box-shadow: inset 0 0 10px #000000;
}
.redsquare {
width: auto;
background-color: red;
}
p {
color: black;
}
<div class="redsquare">
<p>This paragraph before clip image.</p>
<div class="clipimage">
<img src=".jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"; width="350" height="520">
</div>
</div>
<div class="redsquare">
<p>This paragraph before noclip image.</p>
<div class="noclipimage">
<img src=".jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"; width="350" height="520">
</div>
</div>
I'm using Clip-path to cut around an image to make it a smaller rectangle than before. However the box I'm putting it in is treating it like the rest of the image is still there. Is there a way to get rid of the excess portion of the image and just use the clip-path portion of the image?
.image {
width: 20%;
height: 20%;
clip-path: inset(70% 22% 11% 22%);
box-shadow: inset 0 0 10px #000000;
}
I'm trying to fit only that portion of the image somewhere. Outside of forcing it using negative/overlapping the cutout portion, is there another way to go about it?
.clipimage {
width: 20%;
height: 20%;
clip-path: inset(70% 22% 11% 22%);
box-shadow: inset 0 0 10px #000000;
}
.noimage {
width: 20%;
height: 20%;
box-shadow: inset 0 0 10px #000000;
}
.redsquare {
width: auto;
background-color: red;
}
p {
color: black;
}
<div class="redsquare">
<p>This paragraph before clip image.</p>
<div class="clipimage">
<img src="https://images.pexels/photos/19577082/pexels-photo-19577082/free-photo-of-city-skyline-at-dusk.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"; width="350" height="520">
</div>
</div>
<div class="redsquare">
<p>This paragraph before noclip image.</p>
<div class="noclipimage">
<img src="https://images.pexels/photos/19577082/pexels-photo-19577082/free-photo-of-city-skyline-at-dusk.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"; width="350" height="520">
</div>
</div>
Share
Improve this question
edited Feb 3 at 8:37
ProjectPokket
asked Feb 3 at 8:08
ProjectPokketProjectPokket
1551 gold badge3 silver badges14 bronze badges
5
|
1 Answer
Reset to default 1Use object-fit: cover
. That’s the easiest way to turn a bunch of randomly sized and shaped images into neat thumbnails.
body {
background: black;
color: white;
margin: 1em;
}
img {
border: 2px solid white;
}
.gallery {
display: flex;
gap: 1em;
}
.gallery img {
width: 100px;
height: 100px;
object-fit: cover;
object-position: center;
}
<p>random images</p>
<img src="https://picsum.photos/id/670/100/200">
<img src="https://picsum.photos/id/1072/200/100">
<img src="https://picsum.photos/id/1074/150">
<p>turned into a gallery, cropped with object-fit: cover</p>
<div class="gallery">
<img src="https://picsum.photos/id/670/100/200">
<img src="https://picsum.photos/id/1072/200/100">
<img src="https://picsum.photos/id/1074/150">
</div>
clip-path
does. It hides part of the image, it doesn't actually remove it. – Paulie_D Commented Feb 3 at 8:38