What is the best way to ensure my component doesn't get hidden behind my NavBar when using react-scroll?

Currently, I am utilizing react-scroll for smooth navigation through four components. However, when I select a component from the NavBar, it scrolls that component to the top of the screen instead of aligning it with the bottom of the NavBar. To illustrate this issue further, I have included an image displaying how the NavBar obscures some of my content. See Image

Here is a brief overview of my NavBar:

 <nav className="sticky z-10 top-0 font-semibold text-xl bg-nature-green grid grid-cols-3 items-center">
      <a href="home" className="flex no-underline text-black">
        <img
          className="h-8 w-8 "
          src="https://www.freeiconspng.com/thumbs/letter-j-icon-png/letter-j-icon-png-26.png"
        />
        <span>BRAND</span>
      </a>
      <div className="flex sm:justify-center space-x-8 ">
        {[
          ["Home", "home"],
          ["About", "about"],
          ["Products", "products"],
          ["Find Us", "find"],
        ].map(([title, url]) => (
          <Link
            to={url}
            spy={true}
            smooth={true}
            className="p-3 focus:bg-clicked-green hover:bg-selected-green no-underline text-black"
          >
            {title}
          </Link>
        ))}
      </div>
      <div className="flex space-x-8 justify-end">
        {[twitter, twitter, instagram, instagram].map((icon) => (
          <a>
            <img className="h-w right-0" src={icon} />
          </a>
        ))}
      </div>
    </nav>

I speculate that adjusting each component's height to 120% might resolve the excessive scrolling caused by the NavBar. Nonetheless, I prefer not to allocate too much space and hope to discover an alternative solution.

My project utilizes TailwindCSS, where each component has h-screen set for its height. For those interested in reviewing my code, here is the link to my GitHub repository! GitHub Repository

Answer №1

After reviewing your project, it appears that the sticky navbar is causing issues with react-scroll detecting it properly when scrolling down. To fix this issue, you can utilize the offset property within the link component like so:

<Link
  to={url}
  spy={true}
  smooth={true}
  isDynamic={true}
  offset={-110}
  className="p-3 focus:bg-clicked-green hover:bg-selected-green no-underline text-black"
>
  {title}
</Link>

Implementing this adjustment will provide additional padding and prevent your navbar from overlapping with your content.

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

React and Express's session variable does not persist properly

index.js if (result) { console.log("SESSION1: ", req.session) req.session.token = await createAuth(row[0]["user_id"]); console.log("SESSION2: ", req.session) console.log("logged in!", req.session.token) ...

Ways to direct to a specific div upon clicking an anchor tag following a page reload?

<a href="#goto">Link 1</a> <div id="goto">DIV</div> Whenever I click on the anchor tag, my webpage reloads and displays a new div with the ID of goto. This div was previously hidden but is now visible at the bottom of the page. I ...

Unable to assign a className to a personalized React component - troubleshooting needed!

I have a component that relies on another component. I am trying to pass CSS positioning from the outer component to the inner one by using the following code: import OptionsMenu from './OptionsMenu' import { withStyles } from 'material-ui/ ...

Please refrain from initiating the next action until the previous action has been completed

As a beginner, I am currently working on a photo viewer project using JavaScript and jQuery. My main issue arises when clicking on the arrow to view the next picture. I want the current picture to fade out smoothly before the new one fades in. However, th ...

Adjust the height of a <div> element to fit the remaining space in the viewport or window automatically

I am working with the following HTML code: <html> <BODY> <DIV ID="holder"> <DIV ID="head_area">HEAD CONTENT GOES HERE....</DIV> <DIV ID="main_area">BODY CONTENT GOES HERE</DIV> ...

I've been attempting to access a recipe API from recipepuppy.com, but I keep encountering a Syntax Error and 500 Internal Server Error

I have been utilizing the recipepuppy API and encountered an issue while trying to fetch items. I keep receiving an error message, which is related to the following code: search(){ let {ingredients, dish} = this.state; const url =`http://www.recipe ...

Accessing the URL is possible by navigating through the website, but attempting to access it directly through the URL will

After deploying my react app to Netlify, I noticed that when I navigate using the navbar, everything works perfectly. However, if I manually type a URL like https://example.com/contact, I receive a not found error. I am utilizing react-router-dom for nav ...

How to use jQuery to center an overlay on a webpage

Need help with centering a jquery popup on a webpage? I'm struggling with positioning it in the middle of the page, regardless of site adjustments or resolution changes. Currently, I have it set to absolute positioning with CSS, but the issue is that ...

What is the best way to ensure that a card's height matches that of other cards in Material-UI?

Ensuring that 3 horizontal cards have the same height and remain responsive is my current challenge. I've noticed that when one card has more content than the others, it appears taller, creating an uneven look. My goal is to set a fixed height for all ...

How should Bootstrap containers, rows, and columns be properly configured?

As a beginner in Bootstrap, I am still trying to grasp the concepts. Understanding how rows, columns, and containers work is clear to me so far. However, I am struggling with the syntax for setting up the div elements. Should my code look something like t ...

Determination of Vertical Position in a Displayed Table

I am trying to incorporate infinite scrolling with an AJAX-based loader in the body of an HTML table. Here is a snippet of my HTML code: <table> <thead> <tr><th>Column</th></tr> </thead> <tbody> ...

Using functions in props.children

I have been struggling to resolve this issue by referring to multiple Stack Overflow questions, but unfortunately, none of the solutions seem to be working for me. I might not be grasping something correctly despite following the suggested solutions, as I ...

Notifying the Player of Victory in a Javascript Tic Tac Toe Game: The Winning Alert

Recently, I decided to dive into Javascript and kick off my very first game project - a Tic Tac Toe game. If you're curious to see the code for my project, you can check it out here: Tic Tac Toe Project One feature I'm eager to implement is a n ...

What is the reason that em takes precedence over p for font-family?

Take a look at this CSS snippet: * { font-family: Gill Sans, Verdana, Arial, Helvetica, Sans-Serif} p { font-family: Courier; } Now let's consider this HTML markup: <p>Hi there. So <em>very</em> pleased to make your acquaintance. ...

Error: React does not allow objects to be used as a child in @material-ui/Icons

I'm facing a challenge while trying to implement the @material-ui/Icons component in my React project. When I attempt to add the imported icon into my code, I encounter an error message that reads: Objects are not valid as a React child (found: objec ...

Placing a button above another element using CSS styled components

I'm attempting to make a button overlap and be positioned in a specific location on top of a search bar. The current appearance is not what I desire, as the button seems to shift back to its original position when adding a :hover element after applyin ...

The battle between percentages and pixels in fluid design

I am looking to create a flexible layout and would like to achieve the following: width:100%-200px; This means having a div that contains content, referred to as div id="content", with a fixed margin on each side. I have attempted to place the div id="co ...

Navigating through a custom drop-down using Selenium WebDriver: Identifying elements within DIV, UL, and LI

I need assistance automating a custom drop-down field that consists of DIV, UL, and LI elements. Select class or CSSSelector are not viable options due to the dynamic nature of the field. <div id="boundlist-1092" class="x-boundlist x-boundlist-floa ...

Guide on how to show a selection filter next to the table column in Material-Table ReactJS

I am utilizing the tool material-table to showcase table data while also incorporating filters for a specific column located outside of the table. For instance: https://material-table.com/#/docs/features/filtering My goal is to filter only the "birth pl ...

Elevate Your Navbar's Hamburger Menu with Font Awesome SVG in React-Bootstrap!

Currently working with React-Bootstrap to create a Navbar. I have a desire to swap out the default hamburger menu icon provided by React-Bootstrap with a Font Awesome hamburger icon. Wondering what steps need to be taken in order to change the existing bu ...