React component not extending to the bottom of the screen

Within my Index.js file, I have created an Index component that includes a navbar and a landing page layout. I aim to have a showcase section taking up 40% of the width, with the remaining 60% dedicated to a react-bootstrap carousel. The Index component should occupy 100% of the screen height, and the index_body content should be centered and fill the screen's height. However, I am encountering an issue where the index_body only takes the height of its content, leaving white space below it. You can see the issue in this screenshot: https://i.sstatic.net/mtUEA.jpg. When the carousel moves to a slide with a larger image, the index_body height extends beyond 100%. This is demonstrated in this screenshot: https://i.sstatic.net/AOCSe.jpg

function Index() {
   return (
    <>
    <nav className="navbar navbar-dark navbar-expand-sm bg-dark">
        <div className="container">
            <Link to={'/'} className="navbar-brand logo"><h2>XYZ</h2></Link>
            <ul class="navbar-nav ml-auto">
                <li><Link to={'/login'} className='btn btn-dark '>Login</Link></li>
                <li><Link to={'/signup'} className='btn btn-dark' style={mystyle}>Sign Up</Link></li>
            </ul>
        </div>
    </nav>
    <div className='index_body p-4 d-flex' > 
            <div className="info p-2 d-flex align-items-center" style={{width: '40%'}}>
                <div>
                <h1 className="info_heading">Showcase section </h1>
                <p className="info_description">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quis perferendis mollitia nobis labore quasi reiciendis laboriosam aliquid ea eos perspiciatis.</p>

                <Link to={'/login'} className="btn btn-dark" style={mystyle}>Explore Now</Link>
                </div>
            </div>

            <Carousel activeIndex={index} onSelect={handleSelect} style={{width: '60%'}}>
                <Carousel.Item>
                    <img className="d-block w-100" src={firstSlide} alt="First slide" />
                </Carousel.Item>
                <Carousel.Item>
                    <img className="d-block w-100" src="https://images.unsplash.com/photo-1641752084801-80dc709cdf28?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=700&q=60" alt="Second slide" />
                </Carousel.Item>
                <Carousel.Item>
                    <img className="d-block w-100" src="https://images.unsplash.com/photo-1641586822453-e2e5238fa075?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="Third slide" />
                </Carousel.Item>
            </Carousel>
    </div>
    </>

I have already tried:

  • Setting index_body height to 100%
  • Setting index_body min-height to 100%

Answer №1

According to information from mdn,

The percentage is calculated based on the height of the containing block of the generated box. If the height of the containing block is not explicitly specified (meaning it depends on the content height), and this element is not absolutely positioned, the value will be auto. A percentage height on the root element is relative to the initial containing block.

By using height: 100vh; you will achieve the full-page height you are anticipating.

However, if you want the index_body to occupy the remaining height after the navbar, you can implement something similar to the following.

<>
   <nav className="navbar"></nav>
   <div className="index_body"> </div>
</>

Styles

.navbar {
   height: 100px; //example
}
.index_body {
   height: calc(100vh - 100px);
}

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

Increase the size of the image while ensuring the content on the right remains proportionate

I have a challenge with managing two different sizes of images (vertical and horizontal) that need to remain the same size. I am attempting to create a container that can hold the image without affecting the surrounding content, while also possibly using o ...

What is the method to have the text cursor within a text field start a few pixels in?

I need a text field with the cursor starting a few pixels (let's say 4) from the left-hand side. I am aware that this can be achieved by adjusting the size of the text field using padding, but I am curious if there is a way to resize the text box with ...

What is the best way to arrange elements above and below each other in a single flexbox container?

Currently, I am facing a challenge aligning the number 238,741 and the letter N in Number. There is a padding between the Prize Pool div and the Number Active div. All of these elements are enclosed within a parent container with display set to flex and fl ...

Is there a way to redirect the user to a different page without refreshing the page during navigation?

Utilizing javascript, ajax, and jquery to dynamically load content from PHP files without refreshing the page has been a successful venture. However, I am facing a challenge in creating a hyperlink within one of the loaded contents that redirects the user ...

Transforming the material UI popover into a higher order component and storing its state within the higher order component

Currently, I am referencing the react material ui documentation for popovers here. My goal is to consolidate all popover view and state logic within a higher order component. The existing code from the documentation looks like this: function BasicPopove ...

What materials are required in order to receive messages and information through my Contact page?

Currently, I am pondering the optimal method for gathering information from my Contact page. I have already created a form; however, I'm unsure how to send the gathered data to myself since I am relatively new to Web development. Angular is the framew ...

Having trouble submitting a date input form generated with vuejs on Safari browser

I am a huge fan of Vuejs and it's my go-to at work. The other day, I came across a rather perplexing scenario. If you have any insights into this, please do share. Here is the code in question: <script setup lang="ts"> import { ref ...

Using a single AJAX function to write on various tags

Information regarding the likes and dislikes count is retrieved from the server using an ajax function with the following queries: $q3="select count(value) as a from rank where personID='$person' and itemID='$itemID' and value>0 ...

Trouble with React useEffect and onClick button functionality not functioning as expected

App.js import { Container, Row, Col } from "react-bootstrap"; import React, { useState, useEffect } from 'react'; import {person} from "./Data" import DatesCounts from "./Components/DatesCounts"; import DatesList fro ...

When the second history.push is triggered in react-router-dom, it may result in returning an

Hello, I am working with an Antd modal that contains a form. The code snippet for the modal is as follows: <Modal visible={visible} onOk={handleOk} onCancel={handleCancel}> <MyForm onSubmit={handleOpenUrl}> <CustomInput name= ...

After updating the package, webpack is unable to locate the module

I made a simple change to the package version in my package.json, ran npm install, and now I'm encountering an error when starting the webpack-dev-server that says "Uncaught Error: Cannot find module relative path at webpackMissingModule" Here's ...

How to achieve divs with see-through text using CSS?

How can I create a CSS (non-HTML5) based website with a filled div that has a cutout revealing an image underneath? There are various overlays and images involved, making the use of static images inconvenient. Additionally, I anticipate needing to scale th ...

Increasing the maximum width of an image in CSS is necessary to see the max-height take effect

Within my HTML structure: <Col md="6"> <div className="hero-section"> <div className={`flipper ${isFlipping ? "isFlipping" : ""}`}> <div className="front"> <div className="hero-section-content"> ...

Using a ternary condition within the ngClick directive

Trying to implement different functionalities based on the type of device. The setting tab is clickable, and in the desktop version, clicking should redirect to a default URL. However, on mobile devices, clicking the same link should open a modal window. ...

Cookies store their values within the document.cookie framework

My cookie contains the following data: emailID=a1%40a.comSEPmaths=0SEPphysics=0SEPchemistry=0SEPbotany=0SEPzoology=0SEPta mil=0SEPenglish=0SEPpolity=0SEPgk=0SEPhistory=0 However, when I use document.cookie.split('; '), it returns the encoded ve ...

Comparing the use of visibility: hidden with -webkit-transform: translate3d() within a PhoneGap application

Currently, I am creating a hybrid application using PhoneGap. As part of the design, I have several divs (each representing a page) that I toggle between by changing their visibility in CSS using "visibility: hidden" and "visible". However, I recently ca ...

Switch between light and dark modes with the MUI theme toggle in the header (AppBar)

I'm currently working on implementing a feature that allows users to switch between dark and light themes in my web app. The challenge I am facing is how to ensure that this theme change functionality is available throughout the entire app, not just i ...

Animating the maximum height causes a delay in the performance of other elements

Attempting to adjust the maximum height of a ul. When the max-height property changes (via toggling a class), the height shifts immediately, while the items below the ul maintain the animated height as expected. var expander = $('.skill-expand&apos ...

Hover Effect for Instagram Feed (Web Application)

Recently, I created an app using the Instagram API to bring Instagram images into a webapp. As part of this project, I have been diving into CSS to implement a rollover effect where a heart icon appears when users hover over an image. This heart will event ...

Implementing a feature in ReactJS that enables users to select a minimum and maximum limit for checkboxes

I have developed a unique React application that incorporates JSON values into checkbox elements. The JSON data includes both minimum and maximum required values. I successfully implemented a function to set the checkboxes' maximum value based on the ...