Let's say my image size is 960x960, but the height of the img
element is set to 720px.
<img class="imgs" src="~/test.jpg" />
Here are the styles for .imgs
:
.imgs {
width: 100%;
height: 45rem;
object-fit: cover;
}
Can I use object-position
to adjust the position of the image top/bottom or other directions? Is it possible to move the image using specific units?
To illustrate this concept, imagine a black line representing a div and a red line representing the image:
When using object-position: top
, it looks like this:
When using object-position: bottom
:
However, I want to not only align the image at the top with object-position: top
, but also move its content slightly upwards (by a few pixels). I've attempted to achieve this using margin and padding, but it ends up moving the entire element rather than just the content.
My desired result is depicted here: