Make the height of the next/image element 100vh

It's really amazing. I've tried everything to make the image component in nextjs 100vh in height, with automatic width. I've read through all the documentation and examples using the layout property, but nothing seems to work.

Goal: 100vh height, auto width

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;
}

It's easy with html:

<!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>

Can someone explain this to me????

Answer №1

Make sure the parent div is set to relative position

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

.slider {
  display: block;
  height: 100vh;
  position: relative;
}

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

Center text with font awesome symbols

I'm looking for a way to vertically align text next to my FontAwesome icons without using manual padding. Is there a better method for achieving this? https://i.stack.imgur.com/PWwSJ.jpg <div class="row"> <div id="tb-testimonial" class="tes ...

Is it possible to select multiple three.js objects by pressing CTRL and clicking on each one

I'm having issues with implementing multiple selection of three.js objects using CTRL-click. While single-select works perfectly, the behavior is problematic when trying to select multiple objects with CTRL-click. The selected array sometimes contains ...

What is the best way to combine two arrays of objects with varying values for the same key, and add a new object to the mix?

I have two arrays: arr1 = [ { "OwnershipNumber": 0, "ID": null, "Name": "Contractor LLC", "ContrEmployeeTypeId": 0, "ContactEmail": "", "ContactPhone": "", "VeteranEmployeeMilitaryAffiliation": "", "SocialSecurityNumber": ...

What is the best way to fix the "Module not detected: Unable to locate [css file] in [directory]" error when deploying a Next.js website on Netlify?

Trying to deploy my site on Netlify from this GitHub repository: https://github.com/Koda-Pig/joshkoter.com, but encountering an error: 10:02:31 AM: Module not found: Can't resolve '../styles/home.module.css' in '/opt/build/repo/pages&ap ...

Differences Between jQuery Ajax POST Settings and GET Settings

I am in the process of developing a compact plug-in with a strong emphasis on code efficiency and stability. The issue is clearly outlined within the code snippet provided below (further explanation can be found underneath): $(document).ajaxSend(fun ...

Resolving issues with JavaScript onchange functionality

When I try to use both of these scripts (inline and external) together, only the second one seems to be working while the first one does not. The first script (inline) is responsible for submitting the form and loading the list: <select id="my-sel ...

A step-by-step guide on adding a table with colored icons (red, green, and blue) to an HTML page using jQuery

I'm working on a project that requires designing an HTML page with three tables containing images, along with a compare button. Initially, only two tables are visible upon page load, but when the user clicks the compare button, the third table should ...

Utilize Bootstrap 4's d-print classes to style your form

After creating a form that allows users to submit online or print and mail, I encountered an issue with the printing functionality. When using a simple JavaScript print command and applying the .d-print-none class to hide all elements except the form for p ...

"Exploring the Power of Asynchronous Promises within a Switch Statement in

My current controller setup is as follows: app.controller('myController', function ($scope, myService) { $scope.pageData = {}; myService.promiseGetDataFromServer() .then(function (response) { $scope.pageData = response ...

A plug-in for TinyMCE that allows users to adjust column widths within a table

We utilize TinyMCE in our content management system (CMS), and our users have expressed interest in being able to adjust the width of a column within a table. While HTML technically does not recognize columns, the Moodle editor HTMLAREA includes a plugin t ...

extracting both the value and ID attributes from a RadioButtonGroup component in React MaterialUI

I am currently working on extracting the selected value and gameID from a dynamic MaterialUI RadioButtonGroup. Although I have been successful in retrieving the gameID, I am encountering difficulty in obtaining the value: <form onSubmit={this.handl ...

JavaScript Memoization: Enhancing Performance Through Caching

Recently, I delved into various JavaScript design patterns and stumbled upon memoization. While it seems like an effective way to prevent redundant value calculations, I can't help but notice a flaw in its implementation. Consider the following code s ...

Angular makes it easy to perform HTTP requests using the `http

Greetings! Here is the JSON data for "names" : [ { "file": "file1.zip", "date": "12-03-2016", }, { "file": "file2.zip", "date": "24-06-2016", }, { "file": "file3.zip", "date": "02-12-2016 ...

How to apply dynamic styling to a MatHeaderCell using NgStyle?

My goal is to dynamically style a MatHeaderCell instance using the following code: [ngStyle]="styleHeaderCell(c)" Check out my demo here. After examining, I noticed that: styleHeaderCell(c) It receives the column and returns an object, however ...

What is the process for loading a CTM file during startup in the three.js editor?

After encountering this query: How can I create a custom default scene in the three.js editor?, I experimented with loading a .ctm file. Unfortunately, it appears that a different method is needed for this task. What steps should I take to ensure success ...

Angular5+ Error: Unable to retrieve summary for RouterOutlet directive due to illegal state

When attempting to build my Angular App using ng build --prod --aot, I consistently encounter the following error: ERROR in : Illegal state: Could not load the summary for directive RouterOutlet in C:/Path-To-Project/node_modules/@angular/Router/router.d. ...

Why is my Cloud Storage Cloud upload file showing a file size of "0 bytes" (Node)?

I am having issues uploading a PDF file to Google Cloud Storage as the file size appears to be 0 bytes. I have been trying to resolve this for the past 3 days but have not received any response. Here is the code snippet that I am using: const cv = req ...

Is Babel necessary for enabling JavaScript compatibility in my TypeScript React project, excluding Create React App?

This is the webpack configuration for my React project built in TypeScript, module.exports = { mode: 'development', entry: ['./src/main.tsx'], module: { rules: [ { // Rule for ts/tsx files only, no rule for js/js ...

Insert an array of objects into the td elements of a pre-existing table

Currently, I have a table where the td cells are intentionally displayed as blocks. My aim is to insert labels inside each of these td cells by creating spans with specific classes and then prepend them to the table cell. To achieve this, I am utilizing an ...

How to align an element in the center using flexbox while considering the width of the display rather than the available

I need help centering an element that is 100px in width on the display. On either side of this element, there are elements that are 300px and 200px wide. I tried using flexbox to achieve this, but I ended up with two empty spaces or flexible-width element ...