Tips for properly sizing 13 images in Next.js

I've been facing some challenges while working on a responsive website, particularly with getting the sizing right.

When viewing my image on mobile, everything looks good:

https://i.sstatic.net/gNm14.png

However, when I switch over to desktop view, the image appears too large.

https://i.sstatic.net/4u0io.jpg

Here's how I want the image to behave:

On mobile, it should remain at the bottom of the screen as it currently is.

On desktop, I'd like the image to be positioned in the bottom right corner of the viewport within the red rectangle I've outlined. It should resize responsively without fixed dimensions.

The following HTML code is relevant:

<section class="page_hero-section__MZdi7">
   <div class="page_hero-con__ijIdx">
      <a>particulieren</a>
      <h2>(zorg-)organisaties</h2>
      <p>Ontlast de werkvloer. Onze x komen op locatie en zorgen voor een stralende lach voor clienten én medewerkers.</p>
      <button>werkwijze</button><button>get started</button>
   </div>
   <div class="page_hero-join-con__AkBR0">
      <Image alt="cool girl with colorful glasses"
src={coolGirlGlasses}
 \>
      <div>
         <p>werken bij ons?</p>
         <span>
            <hr>
         </span>
         <a>join the crew</a>
      </div>
   </div>
   <div class="page_hero-werkwijze__IoSuu">
      <p>werkwijze</p>
      <div class="page_hero-werkwijze-line__ccNUj"></div>
   </div>
</section>

And here's the relevant CSS code:

.hero-section {
  position: relative;
  display: flex;
  height: calc(100vh - var(--header-height));
  flex-direction: column;
  justify-content: space-between;
}

  img {
    display: block;
    max-width: 100%;
    height: auto;
}

Setting the image height to 100% results in it being larger than its container. I've also attempted using object-fit: contain but that didn't make any difference.

Answer №1

Issue resolved!

I managed to fix it by including the CSS property flex: 1 in the parent element named hero-join-con that contains the img. Additionally, I added fill={true} to the <Image /> react element and applied object-fit: contain along with object-position: right bottom to the hero-con-join img.

The problem with object-fit was due to not having included the fill={true} property previously.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging jQuery's Append functionality

Struggling with using jQuery's .append() method. Check out my code: $('#all ul li').each(function() { if ($(this).children('.material-icons').hasClass('offline-icon') == false) { $('#online ul').append ...

The issue I am facing is that the MDCSelect:change event does not seem to be functioning properly

Is there a way to get MDCSelect:change to work properly before appending all options? If I put MDCSelect:change after the list append, it works but the UI doesn't look right. Question: How can I make MDCSelect:change work without affecting the UI ap ...

Exploring the combination of Tailwind CSS variants with Framer Motion capabilities

Is it possible to integrate tailwind css classes with framer motion objects effectively? const variant = { hidden: { 'w-0' }, visible: { width: 400, transition: { type: 'spring', stiffness: ...

Proper method for implementing critical CSS in a Next.js project to optimize performance and eliminate unnecessary styles

I have set up a NextJS project which can be found here: https://github.com/stefanre1/nextjs-setup Currently, I am looking for the correct method to eliminate unnecessary CSS from TailwindCSS and include critical CSS in each page. Although I have attempte ...

What causes the variation in the appearance of the navigation bar across different pages?

I'm struggling to understand why the Navigation bar has extra padding or margin on top only on certain pages, while it looks fine on the Homepage. I've dedicated countless hours to this issue and I am feeling completely frustrated. If you' ...

Creating a dynamic rectangular design with a taller height than width, featuring perfectly centered content

My website needs a responsive rectangle where I can easily adjust the height and width. However, when I try to rotate the rectangle, the content also rotates 90 degrees. Can anyone help me with this issue? Thank you in advance for any assistance. Snippet ...

The loading icon appears stuck and does not rotate on iOS version 15.3 and above, but functions properly on versions below 15.3

The loading icon does not spin on iOS versions > 15.3 or 16.1, but it works perfectly fine on lower iOS versions for iPhone and iPad, as well as on Android browsers. Below is the CSS code for reference. I've attempted using webkit for Safari and a ...

Middleware in Redux Toolkit is ineffective in managing successful asynchronous actions

After integrating my own middleware into the Redux-Toolkit store using configureStore in my Next.js app, I noticed that the middleware functions appear to be greyed out. I added them via: getDefaultMiddleware({ thunk: { extraArgument: updateNavTabMid ...

In a designated paragraph, set the display of all <span> elements to none using JavaScript

I have a long paragraph with over 10,000 lines of text and I need a way to quickly remove all the lines without hiding the entire paragraph. Specifically, I want to hide each line individually by changing the span style from "display:block" to "display:non ...

Identifying activity on a handheld device

I am currently working on a website and I have noticed that it doesn't work as well on mobile devices as it does on desktop. There are performance issues that need to be addressed. I've seen other websites redirecting users to a different page wh ...

How to maintain HTML list items in a single line while overlaying text

I'm seeking assistance with understanding how to solve a particular issue. I have multiple list elements with varying lengths of text content, each flanked by small images/icons on either side. Below is an example of the HTML structure: .truncate ...

Can HTML/CSS be used to specifically target handheld mobile devices?

I am looking to optimize my video display in HTML by only showing it on desktop browsers. The difference in bandwidth between desktop and mobile devices is affecting the performance of mobile browsers, so I want to target only desktop users. Is there a way ...

The button's color remains static in Internet Explorer despite attempts to change it using a linear gradient background image

I'm curious why the button appears grey in IE and turns blue on hover, rather than starting off blue and becoming darker blue when hovered over. I've managed to make it work in other browsers, but I'm struggling with the code for IE. Thank ...

Ways to rejuvenate an Angular element

Last month, I was called in to rescue a website that was in chaos. After sorting out the major issues, I am now left with fixing some additional features. One of these tasks involves troubleshooting an angular code related to videos and quizzes on certain ...

Accordion checkbox with dynamic features

Currently, I am dynamically populating data into a jQuery accordion. My goal is to include a checkbox just before the <h2> text. <div id="checkbox"> <h2> <span> <input type="checkbox" class="mycheck" value="apple" / ...

Utilizing Apollo Client cache for Server-Side Rendering

Currently, I am utilizing @apollo/client in combination with Next.js for Server Side Rendering. The data retrieval process is via wp-graphql, making it essential to render on the server side. However, there is a minor setback - the cache persists indefinit ...

Add the class "form-group-row" to the "form-horizontal" element

Check out the code snippet here: http://www.bootply.com/h0E7YjPU4n. Is there a way to adjust spacing between input fields while keeping them the same height? Any tips on making input fields uniform in length? ...

CSS Horizontal Menu positioned left losing its background color due to float property

Can you explain why the background color of the ul element disappears when its child elements are floated? I have a vague memory of reading something about floats causing this issue, but I can't recall the details. (JSFiddle) ul { padding-left: ...

`Python automation for seamless HTTP browsing and HTML document generation`

My weekly routine at work involves printing out Account analysis and Account Positions for more than 50 accounts every Monday. I have to navigate through the page, select "account analysis", input the account name, format the page for printing, print the o ...

How to Style a Diamond Shape with Content Inside Using CSS

Can someone help me figure out how to create a diamond-shaped background in HTML? I want the diamond shape to contain text and images, similar to what's shown in this screenshot. The example image uses a background image of a diamond, but I'm loo ...