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

Guide on implementing validation for currency on input field with regular expression

Review the form below: <form> <input type="text" value="" placeholder="Enter no. of employee" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" required/> <input type="te ...

Tips for customizing the color of pagination in bootstrap

I'm currently in the process of designing a website and I've chosen to implement Bootstrap's pagination for navigating between pages. Due to time constraints, I was wondering if anyone knows how I can utilize classes like "bg-dark", "bg-prim ...

Employ a CSS3 media query within a Sass @for loop

Is it really achievable? For instance: @for $i from 1 through 12 { @media screen and (min-width: #{$i * 240}) { width: {$i * 240 + (20*($i-1)) } ; } } However, the issue I'm facing is Invalid CSS after "...nd (min-width: ": expected expre ...

Enhancing user input with multiple values in a textarea using JSTL

I'm having trouble inputting multiple values into a textarea using JSTL. Here is the coding snippet I am using: <label>Resources</label> : <c:forEach items="${MEETING_ENTITY}" var="resource"> <textarea id ...

Issue with border spacing functionality

I'm having some difficulty with my border spacing in CSS. No matter what size I specify, it doesn't seem to have any effect. I just want to use a border for the top line. Here is my CSS: p { border-spacing: 5000px; text-align: right; ...

Side-menu elevates slider

Struggling to keep my slider fixed when the side-menu slides in from the left? I've scoured for solutions without luck. Any expert out there willing to lend a hand? Code Snippet: https://jsfiddle.net/nekgunru/2/ ...

`CSS3 animations utilizing keyframes and transformation`

Looking to replicate a similar effect using CSS animations: I've created a file working with keyframes for the animation, but it's not functioning as desired. My goal is to have the circles complete a full rotation on their axis, starting from ...

Tab panels are shown by Bootstrap 5 tabs

I am using Bootstrap 5 to design a layout that changes based on the width of the screen. When the screen width is greater than or equal to 992 pixels, a table is displayed in the sidebar and some text is shown in the main content area. However, if the scre ...

Ways to emphasize the contrast between two texts using CSS

One method to highlight specific parts of text using CSS can be found in this script: span.highlight { background-color: #B4D5FF; } However, what if we want to highlight the differences between two strings? Take for example these two strings: this ...

Javascript Object and Conditional Statement

I am working on a Dygraph object creation script that includes a data variable. However, I want to avoid passing in this variable for older browsers. Here is the code snippet: function prime() { g = new Dygraph( document.getElementById("g"), d ...

Tips for wrapping the content of a <span> element within a <td> element

Can someone help me figure out how to wrap the content of a <span> tag that is inside a <td>? The style I have applied doesn't seem to be working. Here's the code snippet: <td style="white-space:nowrap;border:1px solid black"> ...

Cleaning up checkbox names by removing unnecessary characters

I'm having an issue with unnecessary characters in the names of checkboxes. There is a certain line var string = "<div class="blblb"><input type="checkbox" name="dasdasads"><input type="checbox" name="adsdsada"></div>"; The ...

Utilize Selenium in Python to choose an element

When working with the following HTML code: <div class="nav-category__col" id="category_nav_level_3" style="display: block;"> <input type="hidden" value="1" name="videogame_type" id="videogame_type"> <ul class="nav-category__list" adp ...

Should all images be set to 100% width with a standard Bootstrap configuration?

For my website project, I decided to incorporate the Bootstrap carousel into the header using version 3.0.3 of Bootstrap. Everything seemed to be functioning correctly until I noticed a strange issue with the image sizes on the page. Initially, all the ima ...

What is the best way to retrieve upload progress information with $_FILES?

HTML: <input type="file" value="choose file" name="file[]" multiple="multiple"/><br/> <input type="submit" class="submit" value="confirm" /> <input type="hid ...

Center an absolutely positioned div using CSS

What is the best way to position an absolute div at the center? <div class="photoFrame">minimum width of 600px, positioned absolutely</div> jQuery var screenWidth = $(window).width(); $('.photoFrame').css({'margin-left': ...

Embed JavaScript code in the head section of the webpage to guarantee its presence even following a page refresh

We recently obtained an innovative Enterprise Talent Management Solution that is cloud-based. One standout feature allows users to incorporate HTML Widgets with scripts on the primary Welcome Page. The customization options for the Welcome Page UI are qui ...

Struggling with aligning Bootstrap 5 navbar items to the right while keeping the brand on the left side?

I'm struggling to align the items to the right on my navbar. No matter what I try, they just won't budge from the left side next to my brand logo. Here's the code I'm working with: <nav class="navbar navbar-expand-lg navbar-dar ...

Something seems to be preventing Div from appearing and there are no error messages appearing

I've been attempting to create a menu, but the toggle div for the menu isn't visible Following a tutorial where an individual sets up a menu, there is a div with a menu icon in the top left corner. Despite meticulously copying the code from the ...

What is the process for installing and utilizing the custom CSSLint rules that I have developed for the command line interface?

After investing a significant amount of time into following the instructions outlined here and here for creating custom CSS linting rules using CSSLint via the CLI, I have successfully generated and tested my own set of rules. However, I am now facing the ...