Change the color of the text when hovering over it

Struggling to update the text color on hover but it remains unchanged.

Using a script to apply the .show class for background changes upon scrolling, which works fine. However, the hover effect for the color CSS property does not take effect.

Various attempts were made to add :hover to alter the color after users scroll down. The goal is to transition from grey to black as users scroll downwards.

.navigation-bar li a {
  display: inline;
  color: lightgrey;
  text-decoration: none;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-weight: bold;
  padding: 10px 20px;
  line-height: 70px;
  transition: 0.2s ease color;
  position:relative;
}
.show:hover .navigation-bar li a {
  color: black;
}
.bg {
  width: 100%;
  height: 70px;
  opacity: 1;
}
.show {
  background-color: #bdbdbd;
  opacity: 0.5;
}
.show:hover{
  background-color: #ebe4dd;
  color: black;
  opacity: 1;
}

HTML:

<div class="navigation-bar">
  <div class="bg transition">

<div id="navigation-container">
  <a href="#"><img src="images/logo.png"></a>

  <ul>
    <li><a href="#title">About</a></li>
    <li><a href="#section1">Projects</a></li>
    <li><a href="#section2">Services</a></li>
    <li><a href="#section3">Get in Touch</a></li>
  </ul>
</div>
</div>
</div>

Codepen

How can I make the text change color on hover after users have scrolled down?

Answer №1

Incorrectly ordered class elements are causing an issue here:

.show:hover .navigation-bar li a {
  color: black;
}

The correct order should be:

.navigation-bar .show:hover li a {
  color: black;  
}

Answer №2

It is essential to create a CSS rule once the class .show is included.

To implement this, include the following line in your CSS stylesheet:

.show  div#navigation-container ul li a{
  color:#000;
}

Answer №3

Perhaps I am misunderstanding, but the code below is designed to alter the text color of the navigation bar when hovered over:

$('#navigation-container').hover(function() {
    $('li > a').css({'color':'black'});
  }, function() {
    $('li > a').css({'color':'grey'});
  });

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

Removing an appended value in jQuery: A step-by-step guide

Here is my code that successfully appends the first item: After clicking the "show count" button, a pop-up dialog box will display the count. However, to remove the appended item or refresh the page, additional steps are required. function showcount() { ...

Issue with Zeroclipboard not copying content when initially clicked

My code is experiencing some issues where it doesn't work on the first click, but strangely works on the second click. $("#btnCopiar").on("click",function(){ var clipBoardObj = new ZeroClipboard($("#btnCopiar"), { moviePath: ".. ...

Dynamically update a dropdown menu with options based on the user's selection from a prior dropdown list using ajax and JSP Servlet

I am working on creating a real-time project for a consultancy and could use some assistance with developing a JSP page. Specifically, I need to allow the user to select a Client (Company name) from a dropdown list. Once a Client is selected, the HR list ...

"JS method for adding elements seems to be doubling instead of adding them

I'm currently experimenting with JavaScript to generate duplicates of a div element upon button click. I've been utilizing the .cloneNode() method, but it seems to be causing an unintended multiplication effect. Initially, there is only one inst ...

I'm having trouble getting my blockquote to work properly. Despite linking the bootstrap CSS and JS files, it still doesn't seem to be functioning

I have connected the downloaded css and js files from bootstrap, but the features are not working as expected. The <blockquote> tag is displaying only plain text, and the <cite></cite> element is not showing "-". What could be the reason ...

Is there a way to give a unique color to a single <a> element with a specific class, differentiating it from the

Apologies if my title is not precise enough. Describing this in just a few words for the title was a bit challenging. Context I am personalizing a template on wordpress.com. The website in question is: I have enclosed the DONATE menu item in a gold-col ...

Using Sass to create unique breakpoints for media queries based on the body class

I am currently in the process of creating a series of web pages that will be accessed from various websites, each with its unique content template. Even though these pages are very similar, they require different media query breakpoints based on the specif ...

retrieving the parent of the a tag from a jquery form

When using the jQuery code below: $('#trade-offer form').on("submit", function(event) { event.preventDefault(); var stock = $(this).closest('.allloopedover'); console.log(stock); return; $.ajax({ url: ajaxur ...

Altering column names in a Pandas DataFrame

I am working on code that generates a table with dates and predictions from a previous machine learning model gv = pd.date_range(str(d1), periods=15) lst_output = pd.DataFrame(lst_output) pred_log = lst_output.apply(np.square) pred = pred_l ...

Obtaining values from an array using jQuery-AJAX formData and passing them to PHP

Attempting to pass an input field with its values in an array along with other input fields into PHP using jQuery-Ajax formData. Everything seems to be functioning correctly except for successfully passing the array values. I've tried numerous methods ...

Styling the Next and Previous Page Links in your WordPress Website

Currently working on developing my own custom Wordpress theme and everything is going well, except for one little detail. I am trying to customize the styling of my next/previous page links so that the next page-link appears on the right side and the previ ...

How to properly align an object in a specified ul, li list

I'm currently facing an issue while building a Joomla site. I have set a background image for my li elements, but the items within the li are not centered as expected. The website I am working on is www.outlawsofhealth.com. The specific list in quest ...

Is it possible to create a query selector that is able to find an element based on its attributes while also excluding elements with a specific class name?

Imagine you have elements that look like this: <div class="a b" data-one="1" data-two="2"></div> <div class="c" data-one="1" data-two="2"></div> <div class="b" data-one="1" data-two="2"></div> Is there a way to selec ...

I can't seem to get my JavaScript to connect to my HTML file. What should I do next?

I'm facing a major issue at the moment. My HTML file doesn't seem to be linking properly with my JavaScript file, even though they are located in the same folder. The script link is correctly placed in the HTML file, but for some reason, it just ...

Avoid repeated appending of data in JavaScript and HTML

I am working with an HTML table and I need to ensure that the values in the second column do not repeat within the grid. Below is the JavaScript code I have written for this purpose: var $addedProductCodes = []; function getProductData(value){ $t ...

Utilizing JavaScript to dynamically update the user interface after submitting a form using jQuery

I am working on implementing an Input element that triggers a form submission: <input type="submit" value="Download" id="downloadButton" class="btn-download" /> The specific requirement is for the button to first execute a javascript function and t ...

Style your ASP.NET page with CSS to create a dynamic layout filled with panels

I'm working on a division that contains panels, but currently they are organized vertically within the division. I'd like to have them arranged next to each other instead. For example: panel_1 panel_2 panel_3 panel_4 panel_5 panel_6 ...

The callback in Jquery getJSON does not execute even when a valid JSON response is received

My server is sending valid JSON objects (as verified by jsonlint.com) that have this structure: "{\"encryption\": {\"key\": \"gKV0oPJwC5CBQxmn\"}}" This is how my HTML file looks: <html> <head> <title&g ...

Using jQuery/AJAX for conducting multiple searches in MySQL

I have created a form where users can input their Name, region, age, and language. I've written a PHP script to retrieve this data but encountered an issue - if a field is left empty or the user starts typing a name and deletes it, the database return ...

PHP code containing an if/else statement that performs form validation and validates the entered date of birth

Currently, I am practicing my PHP skills with if and else statements as well as form validation. The main concept I am working on involves the following: Upon entering a name, Date of Birth (DOB), and email, and then clicking the submit button, the action ...