What is the reason behind the `h-full`/`height:100%` not completely filling the void within a div element?

The issue lies in the structure of my content, which includes a title, a subtitle, and a footer. My desire is for the subtitle's div to fill the gap between the title and the footer.

I attempted using h-full on the div element, but it had no noticeable effect.

export default function ASD() {
  return (
    <div className="flex flex-col justify-start mx-auto w-9/12 min-h-screen bg-red-300 text-center">
      <div className="bg-yellow-200">
        <div className="bg-blue-200 text-6xl">
          <h1>Title</h1>
        </div>
        <div className="bg-indigo-500 text-3xl">
          <h1>Subtitle</h1>
        </div>
      </div>
      <footer className="mt-auto bg-green-200">Footer</footer>
    </div>
  );
}

Furthermore, I aim to ensure that the entire page fills the screen completely, positioning the footer at the bottom of the page.

Answer №1

If your header and subtitle are wrapped inside a div, you should remove that wrapper div. Instead, use flex-1 so that the subtitle div extends across the entire height of the screen.

<div class="mx-auto flex min-h-screen w-9/12 flex-col justify-start bg-red-300 text-center">
  <div class="bg-blue-200 text-6xl">
    <h1>Title</h1>
  </div>
  <div class="flex-1 bg-indigo-500 text-3xl">  //👈 use flex-1 here
    <h1>Subtitle</h1>
  </div>

  <footer class="mt-auto bg-green-200">Footer</footer>
</div>

Output:

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

Tailwind play link

Answer №2

Give this a shot.

<div className="flex flex-col justify-start mx-auto w-9/12 h-full bg-red-300 text-center">
  <div className="bg-yellow-200 flex-1 flex flex-col">
    <div className="bg-blue-200 text-6xl">
      <h1>Heading</h1>
    </div>
    <div className="bg-indigo-500 text-3xl flex-1">
      <h1>Subheading</h1>
    </div>
  </div>
  <footer className="bg-green-200">Footer Text</footer>
</div>

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

How can I ensure that the height of my dropdown menu covers the entire screen without being limited by the page height

I'm trying to adjust a dropdown menu so that it fits perfectly within the screen size, covering the entire height without showing any content beneath or below it. Currently, the menu covers the screen on some pages but scrolls and appears too large du ...

The environmental variables stored in the .env file are showing up as undefined in Next.js 13

I am having trouble accessing the environment variables stored in my .env.local file within the utils folder located in the root directory. When I try to console log them, they show as undefined. console.log({ clientId: process.env.GOOGLE_ID, clien ...

Styling anchors that are focused or visited while scrolling using CSS and jQuery

I'm facing a challenging question that I can't seem to figure out on my own. At the top of my page, I have some anchors that smoothly scroll down to different articles: I would like to indicate to visitors their location on the page by rotating ...

Can anyone assist me with this HTML/jQuery code?

Despite my efforts, I've been unable to achieve success. The challenge I'm facing is with duplicating controls for adding images. I have a button and a div where the user can choose an image by clicking the button. The selected image appears in ...

What is the best way to maintain the selected row during pagination in Yii?

Currently, I am facing an issue with pagination while viewing table rows. My requirement is to select different rows from various pages and then submit the form. The problem occurs when I select rows from one page, navigate to another page to make more se ...

Preventing unclickable Bootstrap checkboxes with identical IDs

I have a checkbox setup like this <div class="form-group"> <div class="col-sm-3"> <div class="checkbox clip-check check-primary"> <input type="checkbox" value="machin ...

What is the best way to update a prop value using a different function?

I have a single component in my NextJs application and I am trying to modify the child prop (referred to as type) of the child component when the <input> element is empty. However, I am facing issues with this task. Can someone please assist me? Tha ...

Tailwind component library - personalize color schemes for your project's design

I recently created a component library using Tailwind and React, and I've utilized Rollup for building the distribution files. In my tailwind.config.js file, you'll find the following color declarations: const colors = require('tailwindcss/c ...

JavaScript's counter variable can become confusing when used in an if statement

Struggling as a beginner in javascript, I find myself stuck on writing an If statement that triggers after the fourth turn. My goal is to have an alert pop up once the user has clicked on four options. The counter variable "turns" was added to track prog ...

React Hook Form is flagging missing dependencies in the useEffect function

Before posting this question, I made an effort to search for a solution on Google. However, I am puzzled by the warning that the linter is giving me regarding my code. The warning message reads: ./components/blocks/Contact.tsx 119:6 Warning: React Hook us ...

Customizing Material UI - Overrides in MakeStyles

Hello there! I'm currently facing a challenge with adding custom CSS to a material UI App Bar. Despite using the makeStyles function, all of my styles are being overridden by the default Material UI styling. The only solution I have found so far is to ...

Transferring onFocus in a React component

Is there a way to hide the yellow title when focusing on an input field? I'm having trouble passing it from the component to use it in the index page. You can view my code at this link. ...

Jquery Not Responding to HasChanged Function

I am a beginner and looking for some guidance. I am attempting to develop a single page app using Jquery and AJAX, but unfortunately nothing seems to be working; no errors or any other indication. There are three hyperlinks with hrefs: #/main, #/second, # ...

Filtering options in a dropdown box with jQuery

I have implemented a feature where the content of one select box is filtered based on the option selected in another select box. Below is the code snippet that achieves this functionality: // Filter content based on the selected option in a region select ...

Looking for assistance with fixing the echo issue in my PHP temperature converter script. Any help is greatly appreciated

Below is my PHP code for converting temperatures: <html> <head> <title>Temperature Conversion</title> <meta charset="utf-8"> </head> <body> <form name="tempConvert" method=&q ...

Clearing browser history with Next Router in Next.js: A step-by-step guide

I have implemented a wrapper that redirects unauthenticated users to the login page: PrivateRoute Wrapper: import { useRouter } from 'next/router' import { useUser } from '../../lib/hooks' import Login from '../../pages/login&apos ...

The issue occurred when the navigator was not properly defined within the node modules

While using Next.js, I encountered an error after running 'npm run dev' (next dev). ReferenceError: navigator is not defined at getChromeVersion (D:\zummon\page\node_modules\jest-worker\node_modules\supports-colo ...

How can I incorporate getInitialProps() into a Higher-Order Component-wrapped functional element in NextJS?

This is a functional component wrapped with a HOC export default wrapperHoc( function myComponent ({ someProps }){ return( <div/> ) }) I'm wondering how to implement getInitialProps for myComponent Is it necessary to call myComp ...

Replicate the preceding input data by simply clicking a button

Here is some HTML and jQuery code that I am working with: $(".btn-copy").click(function() { var previousContent = $(this).prev()[0]; previousContent.select(); document.execCommand('copy'); }); <script src="https://cdnjs.cloudflare.com ...

What's the best way to save data from an HTML input field into a JavaScript array?

Can someone help me with storing a value from an HTML input field into a JavaScript array after a button click, and then displaying that array data on the screen? Here is the HTML code I am currently working with: <!DOCTYPE HTML> <html> < ...