The homepage is displayed below the navigation bar

import Home from './components/Home/Home.jsx'
import Navbar from './components/Navbar/Navbar'
import {BrowserRouter, Routes, Route} from "react-router-dom"
export default function App() {
  return (
    <BrowserRouter>
      <Navbar />
      <div className="container">
        <Routes>
          <Route path="/" element={<Home />} />
        </Routes>
      </div>
    </BrowserRouter>
  );
}

App.css:

.container {
  flex: 1;
  display: flex;
  flex-direction: column;
}

Navbar CSS

import React from "react";
import cart from "../assets/images/cart.png"
import { TfiMenu } from "react-icons/tfi";
import { AiOutlineCloseCircle} from "react-icons/ai";
export default function Navbar() {
  const [open, setopen] = React.useState(false);
  let Links = [
    {name:"Home" ,link:"/"},
    {name:"Headphone" ,link:"/"},
    {name:"Speaker" ,link:"earphones"},
    {name:"Earphone"  ,link:"/"},
  ];
  const change= ()=> {
    setopen(!open);
  }
  return (
    <>
      <div className=" fixed shadow-md w-full  top-0 left-0 ">
        <div className="  lg:flex items-center bg-black py-4 md:justify-around">
          <div className=" flex justify-between px-3 pt-2  text-white cursor-pointer font-[Poppins]">
            audiophile
            <div onClick={change} className=" lg:hidden  w-9 inline-block">
              {
                open 
                  ? (<span className=""><AiOutlineCloseCircle/></span>) 
                  : (<span  className=""><TfiMenu/></span>)
              }
            </div>
          </div>
          <ul className={`lg:flex md:items-center ${open ?"" :"hidden"} `}>
            { Links.map((link) => (
              <li className='  md:ml-8 text-xl md:my-0 my-7'> 
                <a href={link.link} className='text-white hover:text-yellow-500 duration-500'>{link.name}</a>
              </li>
            ))}
          </ul>
          <div className>
            <img className="absolute right-20   md:inline-block  w-7 cursor- top-5 " src={cart} alt="cart" />
          </div>
        </div>
      </div>
    </>
  );
}

I am facing an issue with rendering the home section properly in my code. The top portion of the home page always appears under the navbar. My navbar is positioned sticky and I am unable to make the home width 100%. It seems like it is being affected by another component. Currently, I am using margin-top (mt-44) to adjust the position, but any help or suggestions on how to resolve this would be greatly appreciated.

Answer №1

Consider elevating your container and moving the navbar outside of it as shown in the following code snippet:

import Home from './components/Home/Home.jsx'
import Earphones from './components/Earphones/Earphones'
import Navbar from './components/Navbar/Navbar'
import {BrowserRouter,Routes,Route} from "react-router-dom"
export default function App()
{
return(
<div className="container">
 <Navbar/>
 <BrowserRouter>
 <div className="anothercontainer"> 
         <Routes>
           <Route path="/" element={<Home />} />
         </Routes>
</BrowserRouter>
</div>
</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 retrieve the reference number of an item by clicking a button within a list item in an unordered

Presented here is a collection of data points and a button nested within an ul <ul> <li class="mix" category-1="" data-value="600.35" style="display:block;"> <figure> <figcaption> <h3> ...

Is it considered acceptable to retrieve the action payload in mapDispatchToProps in a React/Redux setup?

In my MediaUpload component, I have a mapDispatchToProps function that handles file uploads. When a file is added, the onChange handler triggers two actions: creating new media entries for the files and updating the form data in the state with the generate ...

The npx command to create a new react-app doesn't seem to be functioning as expected

Encountered errors while running create react-app in the terminal. npx create react-app sample Error: EPERM: operation not permitted, mkdir 'C:\Users\Yasiru' TypeError: Cannot read property 'loaded' of undefined at exit ...

What is the functionality of 'min-height: 100vh' when child elements stack due to a small width?

In a parent element, I have two child elements: <div id="registration"> <div id="left-panel"></div> <div id="right-panel"></div> </div> The styling is as follows: #registration{ @include l { flex-dire ...

Issue with retrieving URL parameters in Nextjs during server side rendering

Currently, I'm attempting to extract the request query, also known as GET parameters, from the URL in server-side rendering for validation and authentication purposes, such as with a Shopify shop. However, I am facing issues with verifying or parsing ...

Upon refreshing the page, nested React routes may fail to display

When I navigate to the main routes and their nested routes, everything works fine. However, I encounter an issue specifically with the nested routes like /register. When I try to refresh the page, it comes up blank with no errors in the console. The main r ...

Tips for adjusting custom spacing margins within Material UI Grid

Is there a way to adjust the spacing between Grid items in Material UI? Here's the code I currently have: <Grid container spacing={1}> <Grid item xs={6}>Node 1</Grid> <Grid item xs={6}>Node 2</Grid> ...and so ...

The library 'react-bootstrap' does not have a 'Grid' export available

I attempted to run npm start, but encountered the following error. ./src/App.js 104:16-24 'react-bootstrap' does not contain an export named 'Grid'. How can I resolve this issue? I already tried running npm install. Is there a substitu ...

ui-router: Issue with ui-sref causing font color to remain unchanged

I've been trying to customize the font color of a navigation link using ui-router's ui-sref functionality, but I'm facing an issue. While I can change the background color by adding it to the .active class in my CSS, the font color remains u ...

What is the best approach for resolving this asynchronous task sequencing issue in JavaScript?

Below is a code snippet where tasks are defined as an object and the function definition should ensure the expected output is met. Let tasks = { ‘a’: { job: function(finish){ setTimeout(() => { ...

Strange behavior observed with CSS intellisense in Visual Code

While working on a ReactJS project, I noticed that when I opt for the style Jsx Attribute for inline CSS, . CSS intellisense seems to not work or only work after I manually add some fields. However, if I manually type the style attribute without using t ...

The adhesive navigation bar isn't adhering

I'm having issues with making my navbar inside a header sticky over the whole page. Despite trying various solutions like removing overflow, adjusting the flexbox, and setting a specific height on the parent element, I still can't get it to work. ...

Support for multiple columns in React JSON Schema Form

Can multi column forms be generated using the React JSONSchema Form Library? I am currently utilizing Material UI for my project. ...

(struggling to deploy) in the process of deploying a PERN application on Heroku

Recently encountered a challenge while attempting to deploy an app on Heroku. My expertise in the deployment aspect of web development is still growing, so it's possible that I'm approaching this incorrectly. The main issue I'm facing is tha ...

Once upon a time in the land of Storybook, a mysterious error message appeared: "Invalid version. You must provide a string

I keep encountering an issue while attempting to set up storybook. Can anyone help me figure out what's causing this problem? npx storybook@latest init • Detecting project type. ✓ TypeError: Invalid version. Must be a string. Got type "obje ...

Tips for accessing the firebase user's getIdToken method in Next.js after a page reload

Currently, I am developing a Next.js project and implementing user authentication using Firebase's signInWithPhoneNumber method for phone number verification. After successful verification, I receive a Firebase user with the getIdToken method to retri ...

The upcoming developer manages to execute the program successfully, however, it continues to load indefinitely

Executing the command yarn dev consistently runs successfully in my VS Code terminal: $ yarn dev yarn run v1.22.19 warning ..\..\..\..\package.json: No license field $ next dev ready - started server on 0.0.0.0:3000, url: http://localho ...

What is the proper way to reference the newly created type?

I came up with a solution to create a custom type that I can easily use without the need to constantly call useSession(), as it needs to be a client-side component. However, whenever I try to access this custom type, it always returns undefined (if I try t ...

What is the most efficient way to evenly separate a CSS3 gradient?

Is there anyone who can assist me in achieving an even gradient break? body { height: 2500px; background: -webkit-linear-gradient(#000000 1%,#FFFFFF 1%,#FFFFFF 13%,#2ecc71 13%,#2ecc71 30%,#3498db 30%,#000000,#FFFFFF,#34495e); } I've been att ...

Adding Breathable Space Between Wrapper and Div Elements

Hello everyone! I am new to the world of web design and this is my first big project. Please bear with me if my code is a bit messy. I need help in reducing the space between my main content area/wrapper and footer to about 20px. Any experts familiar with ...