skip to Main Content

So, I am trying to complete a bento grid challenge from frontend mentor. In one part it requires me to clip/crop an image element and it should not overlap outside the div. I am allowed to use only HTML and CSS for it. Many people have used tailwind for this but I am trying to create it from scratch.

This is what I have done

HTML:

<!-- This div is in a grid container   -->
    <div class="box bento3">
      <h2>Maintain a consistent posting schedule.</h2>
      <img src="./assets/images/illustration-consistent-schedule.webp">
    </div>  

CSS:

  .bento3 > img {
    background-size: cover;
    width: 100%;
    height: auto;
    margin-top: 14px;
  }

This is what it should actually look like

Keep in mind this is not cropping. The image should come up with different screen sizes. For example if I reduce the screen size it looks like this:

For 768px screen size

For 610px screen size

Let me know what I should do to achieve this.

2

Answers


  1. It looks like you’re trying to ensure that the image fits and clips correctly within the grid element while . The issue likely arises because the overflow property isn’t set on the parent container to handle clipping.

    .bento3 {
    display: grid;

    overflow: hidden;
    }

    .bento3 > img {

    width: 100%;

    height: 100%;

    object-fit: cover;

    margin-top: 14px;
    }

    Login or Signup to reply.
  2. Please share your full code for clarification with the image link.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search