Effects of hovering on navigation links in gatsby

I am currently working on developing a static website using Gatsby and I am facing some challenges. I am trying to implement a hover effect for the menu items in the navigation bar, but I am encountering difficulties with the CSS classes including Site-header, wrapper site-header__wrapper, nav__wrapper, and nav__item. I have attempted to make changes to both nav__wrapper.active and nav__item a in the CSS, but have not been successful in achieving the desired result. Below, you can find the HTML and CSS code that I have tried so far. I would greatly appreciate any guidance or advice on how to successfully achieve this hover effect. Thank you in advance.

 * {
      padding: 0px;
      /* padding-bottom: 8px; */
      margin: 0 auto;
      text-decoration: none;
      color: white;
    }
    
    html,
    body {
      min-height: 100%;
    }
    
    body {
      background: radial-gradient(at top left, snow 0%, snow 100%);
      background-repeat: no-repeat;
    }
    .brand {
      font-weight: bold;
      font-size: 20px;
      padding-top: 12px;
      padding-right: 35%;
    }
    
    h3 {
      font-weight: bold;
      font-size: 20px;
      font-style: initial;
      font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
        "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
      color: black;
    }
    
    .site-header {
      position: relative;
      overflow: hidden;
      padding: 15px 10px;
      background-color: white;
      border: 1px snow;
    }
    
    .site-header__wrapper {
      padding-top: 4rem;
      padding-bottom: 6rem;
    }
    @media (min-width: 600px) {
      .site-header__wrapper {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 0;
        padding-bottom: 15px;
      }
    }
    @media (min-width: 600px) {
      .nav__wrapper {
        display: flex;
        gap: 12px;
        align-items: center;
        padding-top: 10px;
        padding-bottom: 0;
      }
    }
    
    @media (max-width: 599px) {
      .nav__wrapper {
        position: relative;
        top: 100%;
        right: 0;
        left: 0;
        bottom: 0;
        z-index: -1;
        background-color: #d9f0f7;
        visibility: hidden;
        opacity: 0;
        transform: translateY(-100%);
        transition: transform 0.3s ease-out, opacity 0.3s ease-out;
      }
      .nav__wrapper.active {
        display: inline-block;
        visibility: visible;
        opacity: 1;
        transform: translateY(0);
        position: relative;
        color: #0087ca;
      }
    }
    
    .nav__item a {
      transition: 0.4s;
      color: #111;
      font-size: 20px;
      text-decoration: none;
      display: inline-block;
      padding: 1.5rem 1rem;
      gap: 10px;
    }
    
    .nav__item a:hover{
      background-color: #ffffff;
      color: #EEA200;
      padding: 24px 10px;
      font-size: 50px;
    }
    .nav__toggle {
      display: flow-root;
    }
    @media (max-width: 599px) {
      .nav__toggle {
        display: block;
        position: absolute;
        right: 1rem;
        top: 1rem;
      }
    }
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="style.css" />
    <title>Static Template</title>
  </head>
  <body>
    <header class="site-header">
      <div class="wrapper site-header__wrapper">
        <h3 class="brand">Community Site</h3>
        <nav class="nav">
          <div class="nav__wrapper">
            <a class="nav__item" href="/Home">
              <h3>Home</h3>
            </a>
            <a class="nav__item" href="/Aboutus">
              <h3>What are we</h3>
            </a>
            <a class="nav__item" href="/Contactus">
              <h3>Contact Us</h3>
            </a>
          </div>
        </nav>
      </div>
    </header>
  </body>
</html>

Answer №1

There are two issues that need to be addressed:

  1. The presence of a space in the :hover selector
  2. You're selecting the nav__item child as an a element instead of an h3

To rectify these problems, I have made the following adjustments which proved to be effective:

.nav__item > h3 {
  transition: 0.4s;
  color: #111;
  font-size: 20px;
  text-decoration: none;
  display: inline-block;
  padding: 1.5rem 1rem;
  gap: 10px;
}

.nav__item > h3:hover{
  background-color: #ffffff;
  color: #EEA200;
  padding: 24px 10px;
}

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

The hover effect for a :before class is not functioning as intended

I have created a dropdown menu with a triangle at the top in this style: When the cursor hovers over only the triangle, it appears like this: However, when the cursor is over the div, the hover effect for both elements is activated as shown here: I am t ...

Create a div element containing a captivating background image that automatically scales to fit any browser window

Currently, I am facing a challenge with scaling background images within a shared div (framework) so that they can resize along with the browser. I have searched for solutions involving Javascript, but none seem to address my specific case. Any assistance ...

The PHP content form is malfunctioning and not processing email submissions properly, resulting in the PHP code being

Following a tutorial, I attempted to create a basic contact form using PHP. As a beginner in PHP, I found the process fairly straightforward, but encountered some bugs in the code. Upon integrating the code on my website, clicking the submit button redirec ...

Display/Hide Location Pins on the Map

Looking for some assistance, please. I'm currently working on a script to toggle the visibility of locations on a map. The main code I've been using can be found here, and my own code is displayed below: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

When utilizing the JavaScript createElement() method to create elements on keydown, it will not be compatible with jQuery's draggable() method

I'm currently developing a drag and drop feature for a project, allowing users to add items to a work area and then position them by dragging. I'm facing an issue where I want to create multiple instances of the same element using a key code, but ...

What is the best way to bring in an external webpage using Jquery and Custom variables into an Iframe?

Is it possible to use JQuery to load a page into an iframe? I have a specific page that generates a custom printable PDF and I want it to be loaded into an iframe for user convenience. Since I utilize jQuery to fetch all the necessary variables, I cannot ...

What is preventing this JSON object from being parsed correctly?

Within my JavaScript file, The process of declaring and parsing the ajax response text is as follows: var subcats = JSON.parse(this.responseText); The actual responseText that needs to be parsed looks like this: {"presubcatId":"1","precatId":"1","presu ...

Styling input[type='date'] for non-Chrome browsers with CSS

Looking for the css equivalent of: ::-webkit-datetime-edit ::-webkit-datetime-edit-fields-wrapper ::-webkit-datetime-edit-text ::-webkit-datetime-edit-month-field ::-webkit-datetime-edit-day-field ::-webkit-datetime-edit-year-field ::-webkit-inner-spin-bu ...

Tips for adjusting the hover size in a navigation bar

I'm currently learning how to use bootstrap and I'm attempting to create a navbar that shrinks when scrolled down, and I also want the hover effect on the links to be full-height. I've tried multiple approaches but haven't been successf ...

Various Plus/Minus Containers

One issue I am facing is that when using multiple counters on the same page, my - and + buttons to decrease or increase the number in a text box do not function properly. The script provided below works for one counter. How can I modify this code so that ...

Tips for creating a mobile-friendly responsive table

I need help with making my table responsive in mobile view. Can someone provide guidance on how to achieve this? Feel free to ask if you have any questions related to my issue. tabel.html I am currently using the Bootstrap framework to create the table ...

The slidedown feature is not functioning as initially planned

As a beginner in HTML, jQuery, and CSS, I am attempting to create a navigation bar that will trigger a jQuery slidedown effect when clicked. Unfortunately, my current code is not producing the desired outcome. Below is a snippet of what I have implemente ...

The video element in HTML5 is not showing up on Safari browsers, but it is functioning properly on Chrome

I have set up a video slider on my webpage. You can view the site The code is functioning perfectly on Chrome and iOS Safari, but there seems to be an issue on desktop browsers. When inspecting the page in Safari, the video elements are present in the HTM ...

The battle between HTML5's async attribute and JS's async property

What sets apart the Html5 async attribute from the JS async property? <script src="http://www.google-analytics.com/ga.js" async> versus (function() { var ga = document.createElement('script'); ga.type = 'text/javascript&apo ...

A step-by-step guide on integrating a Django template tag and HTML element into an HTML page using Javascript

Is there a safe way to insert HTML that includes Django template tags using JavaScript in my project? For instance, if my template contains the following code: <div id="some-element"> <span id="my-tag">{{ my_data }}</sp ...

Accessing a template object in JavaScript using querySelector

Essentially, I am trying to querySelect a <template> from JavaScript but constantly receiving null as the result. JavaScript code: class MyImportWebcomponent extends HTMLElement { constructor() { super(); } connectedCallback() { ...

Troubleshooting JavaScript Object allocation problem

As someone who is not an expert in JavaScript, I have a question that may seem silly. Let's say I have the following snippet of HTML: <div> <script type="text/javascript"> var variable_2 = new SomeObject(); </script ...

Fluctuate the window.location with jQuery or javascript

My goal is to create a functionality where clicking an image will toggle the window.location url between '#' and '#footer'. The current code I have for this is: <script> function clickarrow(){ var rd=Math.floor(Math.random() ...

The PDF format is experiencing compatibility issues when used with the CSS property for page breaks after:

My PDF with CSS page breaks is not functioning properly, as the pages are not breaking as intended. Removing position:absolute solves the issue but leaves space after each page. I suspect it may be a CSS problem, but I'm unsure. If the issue lies wit ...

Seeking assistance with HTML parsing: Struggling to access and parse the complete source code of webhallen.com

When attempting to access and analyze the complete HTML content of this link, I encountered difficulties. Even after clicking "view page source" in my browser, the full HTML code remained inaccessible. ...