N
N
nickilim2021-06-17 18:51:09
css
nickilim, 2021-06-17 18:51:09

How to push an image to the edge to two elements at once?

<div class="main">
  <div class="container">
    <img ...>
  </div>
</div>

In CSS, container has a limited width, while main has a height. How to fit an image to main height and container width?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-06-17
@wapster92

img {
   width: 100%;
   height: 100%;
   object-fit: cover;
}

Set the height to 100% for the container too. It will
work if main has a height explicitly specified

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question