Does the a:hover:not() exception only apply to elements with the .active class?

I developed a navigation bar and split it into 3 distinct sections: 1. id="menu" 2. id="fake" (button to fill space) 3. id="social"

My main goal is to exclude the .active page and the fake button from the hover effect, but it seems that using a:hover:not(.fake) isn't effective. I also wondered if it's feasible to have multiple exceptions.

Here is the complete code:

body{
font-family:'Skranji',sans-serif;
font-size:100%;
margin:0;
}
#nav{
margin:0;
padding:0;
width:100%;
height:35px;
position:fixed;
overflow-y:hidden;
font-size:16px;
letter-spacing:3px;

border-bottom-style:solid;
border-bottom-width:1px;
border-color:black;
}
#nav a:not(.active){
background-color:rgba(0, 0, 0, 0.72);
}
#nav a.active{
background-color:black;
color:white;
}
#nav a:hover:not(.active){
background-color:rgba(128, 127, 127, 0.25);
color:black;
}

#menu{
width:70%;
}
#fake{
width:15%;
display:block;
float:left;
}
#social{
width:15%;
float:left;
}
#menu a{
display:table;
width:25%;
float:left;
}
#fake a{
width:100%;
display:table;
}
#social a{
float:right;
width:33.33%;
}
#menu a,#social a,#fake a{
text-decoration:none;
margin:0;
padding:5px;
color:white;
text-align:center;
}
.rMargin{
margin-right:10px;
}
<!DOCTYPE html>
<html lang="en-us">
  <head>
    <title>Title</title>
    <!-- Required meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->   
        
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="css.css">
    <link href="https://fonts.googleapis.com/css?family=Skranji" rel="stylesheet"> 
  </head>
  <body>
      
    <header>
      <div id="nav">
        <div id="menu">
          <a class="active" href="home.html"><i class="fas fa-home rMargin"></i>Home</a>
          <a href="blog.html"><i class="fas fa-globe rMargin"></i>Blog</a>
          <a href="learn.html"><i class="fas fa-code rMargin"></i>Learn</a>
          <a href="contactMe.html"><i class="fas fa-envelope rMargin"></i>Contact Me</a>  
        </div> 

        <div id="fake" >
          <a class="fake" href="#"><button style="visibility:hidden"></button></a>
        </div>

        <div id="social">               
            <a href="#"><i class="fab fa-instagram"></i></a>
            <a href="#"><i class="fab fa-twitter"></i></a> 
            <a href="#"><i class="fab fa-facebook-f"></i></a>                                  
        </div>
      </div>        
      </header>
    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous"> 
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  </body>
</html>

Answer №1

After some investigation, I figured out the solution! It seems that a:hover:not() only accepts the .active class in my case. Therefore, I had to include the active class in the element where I wanted the exception and then apply another class to restyle it so that it doesn't resemble the .active class directly. This might require a closer look at the code to fully understand, but it's a clever workaround to tackle the issue.

body{
font-family:'Skranji',sans-serif;
font-size:100%;
margin:0;
}
#nav{
margin:0;
padding:0;
width:100%;
height:35px;
position:fixed;
overflow-y:hidden;
font-size:16px;
letter-spacing:3px;

border-bottom-style:solid;
border-bottom-width:1px;
border-color:black;
}
#nav a:not(.active){
background-color:rgba(0, 0, 0, 0.72);
}
#nav a.active{
background-color:black;
color:white;
}
#nav a:hover:not(.active){
background-color:rgba(128, 127, 127, 0.25);
color:black;
}
#nav a.fake{
background-color:rgba(0, 0, 0, 0.72);
}



#menu{
width:70%;
}
#fake{
width:15%;
display:block;
float:left;
}
#social{
width:15%;
float:left;
}
#menu a{
display:table;
width:25%;
float:left;
}
#fake a{
width:100%;
display:table;
}
#social a{
float:right;
width:33.33%;
}
#menu a,#social a,#fake a{
text-decoration:none;
margin:0;
padding:5px;
color:white;
text-align:center;
}
.rMargin{
margin-right:10px;
}
<!DOCTYPE html>
<html lang="en-us">
  <head>
    <title>Title</title>
    <!-- Required meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->   
    
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="css.css">
    <link href="https://fonts.googleapis.com/css?family=Skranji" rel="stylesheet"> 
  </head>
  <body>
      
    <header>
      <div id="nav">
        <div id="menu">
          <a class="active" href="home.html"><i class="fas fa-home rMargin"></i>Home</a>
          <a href="blog.html"><i class="fas fa-globe rMargin"></i>Blog</a>
          <a href="learn.html"><i class="fas fa-code rMargin"></i>Learn</a>
          <a href="contactMe.html"><i class="fas fa-envelope rMargin"></i>Contact Me</a>  
        </div> 

        <div id="fake" >
          <a class="active fake" href="#"><button style="visibility:hidden"></button></a>
        </div>

        <div id="social">               
            <a href="#"><i class="fab fa-instagram"></i></a>
            <a href="#"><i class="fab fa-twitter"></i></a> 
            <a href="#"><i class="fab fa-facebook-f"></i></a>                                
        </div>
      </div>        
      </header>

    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous"> 
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  </body>
</html>

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

Showcasing Wordpress blog entries on another webpage

Struggling with understanding how to showcase posts from a Wordpress blog on a website? You're not alone. Imagine you have a website www.site.com and a blog structured in Wordpress located at www.site.com/blog. Your task is to feature the recent post ...

"Engaging with the touchscreen inhibits the triggering of click

Within this div, I have implemented touch-action:pan-y;. Surrounding this div is an anchor tag. If you click on the div, the link will successfully redirect. However, if you swipe on the div and then click, the link won't work on the first attempt bu ...

Is there a way to display multiple images in a JSON message object?

If you're looking for a fun way to generate random dog images, then check out my DogAPI image generator! Simply enter a number between 1-50 into the form text box, hit send, and watch as it displays that amount of random dog photos. I'm almost t ...

What could be causing the issue with the width: 100% not rendering correctly in this

I'm currently working on my footer, but I'm having trouble getting the width: 100% tag to work correctly. Here's a screenshot of what I mean: http://gyazo.com/9c23897cd7b9a74ca55ee9fb977f810c This is my CSS code: /*..Portfolio - Lars Beut ...

Ensure to validate the character length prior to saving data using an ajax request

When I try to save data using ajax/jquery, the character length pattern check does not work as expected. The form tag includes: pattern=".{6,}" oninvalid="this.setCustomValidity('Password must be at least 6 characters')" Below is the form and a ...

Building and saving an HTML webpage using Node.js: A step-by-step guide

Using node.js, I developed an application that gathers data in a MongoDB database. For example: name: John pagename: mypage links: [link1, link2, link3] The task at hand is to generate static HTML pages with the format pagename.mydomainname.com, and ins ...

Design a custom screensaver using jQuery that includes a timed delay feature and an alert message

I am currently working on implementing a screensaver feature for my website. Here is the breakdown of what I am trying to achieve: When detecting the onload, clicks, and touches, I want to start a timer that counts 5 seconds. If any of these events are d ...

Suggestions for creating a <div> that takes up the entire space when using the display property set to flex

html, body { height: 100%; margin: 0px; } .container { display: flex; width: 100%; height: 100%; background-color: yellow; } .box { flex-shrink: 0; } <div> <div class="container"> <div class="box"&g ...

How can I animate scrolling up or down using jQuery and CSS?

I have a a element that triggers an action when clicked: <a href="#" class="hel" onclick="YPCP1_();">Scroll down</a> Also, function YPCP_(){ var scroll = $(window).scrollTop(); window.scrollTo(0, 600); } The function successfully sc ...

.css files standing their ground against modifications

Currently, I'm utilizing the WebStorm IDE to work on my React project. My goal is to make modifications to the app.css files in order to update the design. However, each time I attempt to build or run the project, it dismisses all of the changes I&apo ...

What is preventing the items inside the <ul> element from displaying?

Struggling to grasp pagination, I can't figure out why the contents of "li" under the "ul" disappear while the "ul" container continues to display despite specifying in the JavaScript that only 6 should be visible on the page. The "ul" and "li" elemen ...

Tabbed form design using Twitter Bootstrap

Currently, I am working on a website using the Bootstrap framework. My goal is to create a single page that features a pop-up form with two or three tabs. Specifically, I envision these tabs as "The Markup," "The CSS," and "The JavaScript." While I have ma ...

What is the process for generating a HORIZONTAL navigation bar in a CGI Perl script?

Currently, I have a CGI page called Login.cgi. It features a form where I must input the correct password to be redirected to another page named Main.cgi. On this new page, my goal is to incorporate a HORIZONTAL menu containing options like UsersList, Logs ...

Understanding the hierarchy of LESS css class structure is crucial for

In my chat contact list, each contact can have a different state represented by classes: .online .offline .online .selected .offline .selected Here are the corresponding styles (example): .online { background-color: #fff; p { color: #000; } } . ...

How can I use htaccess to forward all links within a specific folder to index.php with a GET variable attached?

Is it possible to redirect all links inside a folder to index.php while passing the file name as a GET variable? I have never worked with htaccess before and don't know how to search for it. For instance: localhost/folder/file-123 should redirect to ...

What HTML5 form JavaScript polyfill offers the most extensive functionality and compatibility across different browsers?

The improved attributes and tags introduced in HTML5 are quite beneficial. Unfortunately, support for these features is limited in Chrome and Firefox, with virtually no support in IE9 and earlier versions. After researching, I have come across Modernizr a ...

Leveraging jQuery functions with dynamically generated DOM elements in JavaScript

On my website, I have a button that dynamically generates a dropdown menu, a textfield, and two buttons when clicked. The purpose of the textfield is to track the quantity selected, while the two buttons allow users to increase or decrease the value by 1. ...

Adjust the size of an image to fit within a set height row using CSS grid

I have a container with fixed width and height where I want to display an image and some text. My goal is to have the text appear first, followed by the image filling up the remaining space in the container. Check out the image below for reference: Exampl ...

What is the best way to create grid designs using less in bootstrap?

When using Bootstrap without a preprocessor, we include classes directly into our opening tags like this: <div id="El" class="col-md-1"></div> Personally, I usually work with Bourbon Neat and Sass. With Sass, I can import mixins in the rules ...

The layout of my website is perfect when my laptop's zoom is set to 90%, but at 100% it starts overflowing

Currently, I am in the process of building a website on my laptop while following an instructor's video tutorial. It has been important for me to set the same pixel measurements as the instructor in order to replicate the design they provided. However ...