What is the best way to create an active class that remains on my page, adding a stylish border effect?

I have been working on a project where I have created an animation effect for every link that users click on, triggering an animation before redirecting to the desired page. However, I am facing an issue with adding a bottom border below the current navbar.

.index.html

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <nav class="new__parent-navbar">
      <div class="new__logo">
        <a href="/getdata/startups" class="logo-link"
          ><h1 class=""><b>Header-issue</b></h1></a
        >
      </div>

      <div class="new__navbar h-nav">
        <ul class="new__nav-list v-class">
          <h4 class="">
            <li class=""><a href="/home.html">HOME</a></li>
          </h4>
          <h4 class="">
            <li class=""><a href="/about.html">ABOUT</a></li>
          </h4>
          <h4 class="">
            <li class=""><a href="/contact.html">CONTACT US</a></li>
          </h4>

          <h4 class="">
            <li class=""><a href="/job.html">JOBS</a></li>
          </h4>
          
        </ul>
        
        <h4 class=""><a class="login-nav" href="/login/startup">LOGIN</a><</h4>
      
      </div>
      
      <br />
      <br />
     
      <!-- <div class="rightNav v-class">
            <input type="text" name="search" id="search">
            <button class="btn btn-sm">SEARCH</button>
            <h1>rightnav</h1>
        </div> -->

      <div class="new__burger">
        <div class="new__line"></div>
        <div class="new__line"></div>
        <div class="new__line"></div>
      </div>
      
    </nav>
    
    <script>
      burger = document.querySelector(".new__burger");
      navbar = document.querySelector(".new__navbar");
      // rightNav = document.querySelector('.rightNav')
      navlist = document.querySelector(".new__nav-list");
      black = document.querySelector(".b-black");

      burger.addEventListener("click", () => {
        navbar.classList.toggle("h-nav");       
        navlist.classList.toggle("v-class");
        navbar.classList.toggle("b-black");
      });
      
      window.addEventListener("scroll", function () {
        let header = document.querySelector("nav");
        header.classList.toggle("sticky", window.scrollY > 0);
      });

    </script>
  
  </body>
</html>

style.css

[CSS styles here]

contact.html

[Contact Page HTML Content]
and so on and all the rest about contact and job remain the same

Answer №1

Did you attempt to remove the / in front of your page name?

Replace

<li class=""><a href="/contact.html">CONTACT US</a></li>

With

<li class=""><a href="contact.html">CONTACT US</a></li>

Answer №2

Your webpage is lacking semantic HTML code. The active class on the current page should be associated with either the <li> or <a> elements to function properly.

All you need to do is remove the <h4> tags from the <li>s.

To clarify, restructure like this:

<ul>
    <li></li>
</ul>

Apply bold/size styling using CSS to achieve the desired effect.

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

Angular Filtering: Enhancing User Search Experience [Part 2]

When attempting to import the 'CommonModule', I encountered the same error message. However, when trying to write "of" between car and cars, it highlights the word filter as an error and displays: No pipe found with name 'filter'. I am ...

Inserting Text with Line Breaks into a Textarea Using jQuery and PHP MySQL

I am dealing with a form that users complete with a textarea input. This form is saved into a MySQL database, and later the user has the ability to make edits. The problem I am facing is that whenever I try to use AJAX to provide suggestions for the textar ...

What is the best way to ensure that the React useEffect hook is triggered only once following a state change

I am brand new to the world of React hooks and I'm facing a specific challenge. Imagine that we have two states, state1 and state2, and we are using the useEffect hook to call asyncFn1 and update state1. My goal now is to wait for a change in state1 ...

Minimize CPU consumption in your threejs application

I've been working on a project where I'm coding Snake in Threejs (I know there are simpler methods). Everything works smoothly until the snake reaches a certain size, causing CPU usage to spike to 50% or more and freezing the entire browser tab. ...

jQuery's inArray function producing inaccurate outcomes

I am attempting to verify the presence of a specific string within an array of strings. console.log($.inArray(String(value.value), selectors) > 0, String(value.value), selectors); The results from the code snippet are as follows: false "23" (2) ["23", ...

Highcharts displays data with the fourth y axis but doesn't include labels for it

I'm facing an issue with displaying all the labels on my chart. I have 4 series plotted and decided to add two y-axes on each side of the graph, but the labels for the last series named "Stuff Data" are not showing up correctly. Instead, it seems to b ...

Refreshing MongoDB data by utilizing values from an object

I am facing a challenge with my MongoDB collection structure: [ { "stock": "GOOGLE", "price": 0 }, { "stock": "FACEBOOK", "price": 0 } ] On the other hand, I have a Stock_P ...

Tips for executing a function once data is received from the .subscribe() method in Angular 5

I am struggling to find a solution that works. I am currently subscribing to an observable in the following way: this.contentfulService.weekNumber .subscribe( (weekNumber) => { this.weekNumber = weekNumber; } ); Once the data is receiv ...

Troubleshoot: Bootstrap Tooltips visible in DOM but not functioning

I am currently attempting to utilize bootstrap's tooltip feature on a dynamically created set of divs. When hovering, I can see in Chrome's inspector that the div itself is being modified correctly (title value is passed to data-original-title) a ...

Utilizing the Vuex/Redux store pattern to efficiently share a centralized source of data between parent and child components, allowing for customizable variations of the data as

Understanding the advantages of utilizing a store pattern and establishing a single source of truth for data shared across components in an application is essential. Making API calls in a store action that can be called by components, rather than making se ...

Regex to Capitalize First Letter of Word with More Than Three Characters

I'm working on coding something in React and I'm trying to use Regex to capitalize the first letter of any word that is more than 3 letters long. I've been struggling with finding the right Regex pattern, despite researching a lot of resourc ...

Using PHP's DOM to extract the text within a td class

I'm brand new to working with the Document Object Model (DOM), so please be patient with me. I am attempting to extract specific content from a web page where there are citations, with the webpage URL. The target element I'm trying to access is: ...

Using the symbols ${} and {{ }} in jQuery templates can help organize and output data in

What is the most effective method for displaying literal ${} and {{ }} strings with JQuery templates? I require this functionality in order to create templates that can dynamically generate other templates. ...

Error in Vuex when attempting to modify a local version of the state leads to a mutation issue

I'm facing a perplexing issue in my Vue application that has left me puzzled. The error message I'm encountering when trying to update a local version of a state element reads as follows: Error: [vuex] Do not mutate vuex store state outside mu ...

The text alignment is set to center, however, the wrapper, input boxes, and button are not aligning themselves in the center. The logo

Within this webpage, there exists a logo image file with a specified height to ensure proper fit. The logo positions itself beautifully within its designated div, with the wrapper div containing text-align: center, resulting in perfect alignment. Additiona ...

Is it possible to enhance a form box with a border?

Having trouble adding a border to my bootstrap form box. I've tried applying border style properties but it doesn't seem to be working. Any suggestions? This is the class for the form box: <div class="form-box"> <div ...

Instructions on creating a solid wall in Three.js using boxGeometry to prevent objects from passing through

I recently created a 3D maze using threejs, where I utilized BoxGeometry to construct walls that the game object cannot pass through. In my research, I discovered the importance of collision detection in ensuring the object does not go through the wall. ...

Display the information by using the getJSON function and iterating through it with

I am working on a project where I receive JSON encoded data from a PHP script using $.getJSON. This data consists of 10 datasets that I want to display by fading out the old content, replacing it with the new one, and then fading in the updated information ...

How can we effectively share code between server-side and client-side in Isomorphic ReactJS applications?

For a small test, I am using express.js and react.js. Below you can find my react code: views/Todo.jsx, var React = require('react'); var TodoApp = React.createClass({ getInitialState: function() { return { counter: 0 ...

Leveraging NgRoute Params within an AngularJS Controller Identifier

In AngularJS, I have successfully set up a route with a variable parameter. This question is an expansion on this previous inquiry; where I was able to utilize params in a variable templateUrl like this: .when('/course/:lesson', { templateU ...