Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Set height 100vh for next/image

it's incredible. I have tried with all means to get the image component of nextjs to 100vh, width is supposed to be automatic. I went through the whole documentation and its examples with the layout proerty, but nothing fits.

Target: height 100vh, width:auto

import img6 from "./image.jpg";

import styles from "../styles/slider.module.css";

export default function about() {
  return (
    <>
      <div className={styles.slider}>
        <Image
          alt=""
          src={img6}
          // layout="responsive"
          // layout="fill"
          // objectFit="cover"
          className={styles.image}
          // style={{ height: "100vh" }}
          // width="300px"
          // height="100%"
        />
      </div>
    </>
  );
}
.slider {
  display: block;
  height: 100vh;
}

.image {
  height: 100vh;
  width: auto;
}

With html it is easy:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .img{
            height: 100vh;
        }
    </style>
</head>
<body>

<img src="http://placeimg.com/640/480/animals/sepia" alt="" class="img">

</body>
</html>

kann mir das jemand erklären????

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

The parent div should have position relative

<div className={styles.slider}>
    <Image
        alt=""
        src={img6}
        layout="fill"
    />
</div>

.slider {
  display: block;
  height: 100vh;
  position: relative;
}
about 4 years ago · Santiago Gelvez Report

0

For those who are interested, I solved it using layout='raw', which is still experimental.

Related Github Issues:

  • https://github.com/vercel/next.js/issues/18637
  • https://github.com/vercel/next.js/issues/35493

And next.config.js:

experimental: { images: { layoutRaw: true } }
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!