0

I have an image that I would like to stretch itself out so there is no whitespace on the right whilst maintaining its aspect ratio and just cutting some of the image out of view. I also want to have the image the same size as the blue container. I tried some solutions on here such as setting the max width of the image to 100% and using object-fit: cover I but haven't figured it out yet. enter image description here

* {
  margin: 0px;
  padding: 0px;
}

.see-bike-rides-card {
  display: flex;
  max-height:400px;
}

.home-card-text {
  background: #80D0E5;
  padding: 1rem;
}

.see-bike-rides-card {
  max-height: 400px;
  width: 1000px;
}

.see-bike-rides-card img {
  width: fit-content;
  max-height:400px;
  object-fit: cover;

}
<article class="see-bike-rides-card">

  <section class="home-card-text">
    <h2>Coolest Bike Rides in Brisbane</h2>
    <p>Check out our favourite spots
      to ride your bike in Brissy.</p>
    <div>
      <a href="#" class="button">See Bike Trails</a>
    </div>
  </section>
  <section>
    <figure>
      <img src="https://images.unsplash.com/photo-1515722265856-49cdff079949?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8" alt="">
    </figure>
  </section>
</article>

2
  • Is object-fit: fill meet your demand? Commented Oct 6, 2022 at 3:30
  • i tried it but it sadly didn't change anything. Commented Oct 6, 2022 at 3:37

3 Answers 3

1

If you set the sections to be 50% width so they are equal, then set the figure to be 100% height & width to fill the space, with object-fit cover will get the image to fill the area.

* {
  margin: 0px;
  padding: 0px;
}

.see-bike-rides-card {
  display: flex;
  width: 100vw;
  height: 100vh
}

.see-bike-rides-card section {
  width: 50%;
}

.home-card-text {
  background: #80D0E5;
  padding: 1rem;
}

.see-bike-rides-card figure {
  display: flex;
  width: 100%;
  height: 100%;

}
.see-bike-rides-card img {
  object-fit: cover;
    width: 100%;
    margin: auto;
  height: 100%;
}
<article class="see-bike-rides-card">

  <section class="home-card-text">
    <h2>Coolest Bike Rides in Brisbane</h2>
    <p>Check out our favourite spots
      to ride your bike in Brissy.</p>
    <div>
      <a href="#" class="button">See Bike Trails</a>
    </div>
  </section>
  <section>
    <figure>
      <img src="https://images.unsplash.com/photo-1515722265856-49cdff079949?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8" alt="">
    </figure>
  </section>
</article>

Sign up to request clarification or add additional context in comments.

4 Comments

when you run this code by clicking expand snippet unfortunately it is not filling the screen
Thats just the height of the .see-bike-rides-card, change the min-height/max-height values to get what you want.
it is the width, i can share a picture if you need
I just added 100vh to the .see-bike-rides-card it will now fill the screen.
0

In

.see-bike-rides-card

Change max width to 100% as well.

1 Comment

with width at 100% it doesnt change anything. You have to click the expand snippet button to see the code snippet in full screen I should have stated that in the post sorry
0

Using inline-style will only solve the problem you can use max-width or width:

<img src="https://images.unsplash.com/photo-1515722265856-49cdff079949?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8" style="max-width=100%; object-fit:contain"alt="">

1 Comment

Try the inline-style I added to the image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.