Height of a React Component

I have developed a React component for the homepage of my React application. Utilizing React Router, I am able to navigate through different components on the site. The issue I'm facing is that the homepage component does not occupy the entire page except for the navbar section.

Here is my Home.js (homepage component)

import React from 'react';
import './Home.css';

export default function Home() {
    return (
        <html>
            <body>
                <div class="home">
                    <h1>Home Page</h1>
                </div>
            </body>
        </html>
    )
}

This is my navbar

import React from 'react';

export default function Navbar() {
    return (
        <div>

<nav class="navbar navbar-expand-sm bg-dark navbar-dark py-0">

  <a class="navbar-brand" href="/">Planet Code</a>


  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="nav-link" href="/about">About</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link 2</a>
    </li>

  </ul>
</nav>

        </div>
    )
}

This is my App.js

import React from 'react';
import Navbar from './components/Navbar';
import About from './components/About';
import {
  BrowserRouter as Router,
  Switch,
  Route,
  Link
} from "react-router-dom";
import Home from './components/Home';

function App() {
  return (
    <>
    <Navbar />
      <Router>
      <div>
        {/* A <Switch> looks through its children <Route>s and
            renders the first one that matches the current URL. */}
        <Switch>
          <Route path="/about">
            <About />
          </Route>
          <Route path="/">
            <Home />
          </Route>
        </Switch>
      </div>
    </Router>
  </>
  )
}

export default App;

This is a snapshot of the site https://i.sstatic.net/ORpk6.png

Answer №1

To make the home section of your page larger, you can set a minimum height of 100vh and then subtract the height of the navbar using CSS calc() ...

.home {min-height: calc(100vh - 80px);} 

... where 80px represents the height of your navbar.

Alternatively, you can utilize Flexbox with flex-grow: 1 as demonstrated in this solution.

On a related note, the structure of your HTML is not semantically correct because your Navbar HTML is located outside of the Home component <html> tag.

I recommend moving the

<html><body></body></html>
tags into your App component so that Nav and Home are properly nested within the app's html structure.

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

Click to reveal sliding menu bar

Trying to create a sliding menu bar (.top-bar) that activates when clicking an arrow (#hide), causing the arrow to also slide up and switch from an up arrow to a down arrow. Here is my unsuccessful attempt: $(document).ready(function(){ $("#hide").c ...

Is it a bug that using addClass or toggleClass with JQuery inside a click method does not seem to be functioning properly?

This appears to be a simple issue, yet it is not functioning correctly. I managed to make it work by placing the .normal class above the .highlight class, despite only adjusting the position and not altering the style. This lack of logic is puzzling. Sin ...

What is the best way to generate a fresh set of data from a search parameter?

I have received data from an API call that needs to be filtered. I am utilizing Redux instead of local state for this task. Below are the actions I have defined: import ActionTypes from '../constants/ActionTypes'; export const passengersDataAc ...

Question about Selecting Boxes

I'm looking for the name of the HTML tool that is used to create a list of objects from a select field. It typically consists of two boxes with an arrow in between them. For example, when creating a group, Box A would contain a list of users and you c ...

Issues with Javascript Date Function malfunctioning

I'm having trouble getting the text 'Oct 09, 2012' to display properly. Instead of running the function correctly, a bunch of unnecessary date text is showing up. Can anyone figure out what I'm doing wrong? Feel free to experiment with ...

Error: Unbalanced parentheses detected in the argument list at file path C:UsersgajjaOneDriveDesktopuser_loginviewsupdate.ejs during ejs compilation

When I try to update, instead of showing the form fill field, an error pops up. Can someone assist me with this? <!DOCTYPE html> <html> <head> <title>Form Data</title> </head> <body> <h1>Form Dat ...

Leveraging jQuery for Custom Form Styling

.I prefer to utilize personalized form elements in my forms. <fieldset> <legend id="Cities">Urban Areas</legend> <div class="legend-underline"></div> <div class="filters" id="Cities-filters"> <div> < ...

Using Python to manipulate HTML for printing purposes

As I develop an application in Python, one of the features requires printing PDF files using a Xerox printer. I am currently considering two options: First option: figuring out a way to communicate with the printer driver and send commands to the printer ...

The file index.html seems to be missing - encountered an error while pushing to Heroku

After attempting to deploy my react-node app to Heroku using Heroku CLI, I encountered an error during the build process stating that it could not find the required file index.html. I have thoroughly checked all the files and confirmed that everything is ...

Tips for aligning text to match the starting point of other text

Currently, the text appears as follows: Lorem ipsum dolor sit amet consectetur adipiscing elit vitae orci elementum dictum I want it to look like this: Lorem ipsum dolor sit amet consectetur adipiscing elit vitae orci elementum dictum I ...

Press on a rectangle inside an HTML5 SVG program

I'm currently developing a web application that utilizes the svg and Raphael library: workflowEditor.show(); var myList = document.getElementsByTagName("rect"); for (var a = 0; a < myList.length; a++) { myList[a].addEventListener("OnClick", f ...

Tips for loading all background images simultaneously

I just created my first website page with a few background images that crossfade. However, I am experiencing an issue where the next background image takes some time to load during the crossfading effect if the page is not cached on the user's comput ...

I designed three interactive buttons that allow users to change the language of the website with a simple click. While my JavaScript code functions perfectly on local host, it seems to encounter issues when deployed

For those interested, the live server can be accessed at . After creating 3 buttons that change the language of the website when clicked, the issue arose where the JavaScript code worked perfectly on localhost but failed to function properly on the online ...

Issue with floating navigation bar functionality when resizing the page

After much tinkering, I have managed to create a floating navigation bar for my website. Most of the time, it works perfectly fine, but there's an issue when the window size is adjusted in the floating mode. Take a look at the image below for referenc ...

Display tables based on selected changes with dynamically changing options

My HTML structure displays rows with active and inactive statuses based on a select change, and it's currently functioning correctly. However, the project requirements have changed, allowing for more status options besides just active and inactive. I ...

What is the correct TypeScript type to use for generating an element?

Can you determine the return type in this scenario? The paths value is a function that generates an element. export type iconName = "logo"; type icon = { viewBox: string; paths: () => ??; }; const IconSetCollection: Record<iconNa ...

The art of arranging React components

I'm struggling to organize my react components properly and I'm having difficulty with CSS Flexbox. Here are the 3 react components: function App() { return ( <> <div className = "header"> <h1>Connect ...

CSS Positioning: the container is not the right size for its content dimensions

Code Snippet: <div content> <div post> <div post> ... </div> Styling: .post { margin: 0; padding: 110px 20px 20px; float: left; width: 560px; position: relative; display: block; } #content { display ...

Access is restricted by Firebase when attempting to utilize the env file

I am in the process of developing a react-app that integrates with Firebase. The typical setup for credentials is as follows: const firebaseConfig = { apiKey: ..., authDomain: ..., projectId: ..., storageBucket: ..., messagingSenderId: ...

Experiencing difficulties with JSoup on Android for HTML parsing

I recently started working on a fun little project to scrape data (specifically XKCD comics) from the internet and display it on my phone. This is my first time delving into Android development, and since I'm not too familiar with Java, I'm keepi ...