Shrinking Navigation Menu - Changing Font Color

I'm attempting to update the menu text color when the header shrinks on scroll.

I've experimented with this code:

$(window).scroll(function() {
  if ($(document).scrollTop() > 20) {
    $('ul.art-hmenu>li>a').addClass('shrinkmenufont');
  } else {
    $('ul.art-hmenu>li>a').removeClass('shrinkmenufont');
  }
});

using:

.shrinkmenufont {
  font-color: black;
}

The function runs, but the font color stays white and doesn't switch to black as intended when scrolling down.

Any advice would be greatly appreciated.

Thank you!

Link:

Website

Answer №1

There are a couple of issues to address here. Firstly, when it comes to changing text color in CSS, the correct property is simply color, not text-color. Secondly, the rule that specifies the color as orange is

ul.art-hmenu > li > a.active
, which has higher specificity compared to just .shrinkmenufont. To ensure that the text appears in black, you will need to make your rule more specific or place it after the orange rule. You can try this:

ul.art-hmenu > li > a.shrinkmenufont {
    color: 'black';
}

Answer №2

Here is the simple CSS code to change the font color of the resized header:

The CSS code snippet is as follows:

.shrinknav a.shrinkmenufont {
  color: #000;
}

Answer №3

$(window).on('scroll', function() {
   if ($(document).scrollTop() > 20) {
       $('ul.art-hmenu>li>a').css('color', 'black');
   } else {
       $('ul.art-hmenu>li>a').css('color', 'white');
   }
});

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

Determine the total value derived from adding two option values together

I am attempting to calculate the sum of two select options and display the result. So far, my attempts have only resulted in returning the value 1. What I am aiming for is to add the values from n_adult and n_children, and then show the total under Numbe ...

The div element is refusing to display the background image

I'm struggling to add images as background to a div. When I try inline styling, the background-image appears fine. However, when I attempt to use an external CSS file, the image does not show up. I have carefully checked the link and made sure that t ...

Retrieving JSON data from an API

As a beginner with Jquery JSON and API's, I am trying to work on hitting an API that returns city names in JSON format. I need to display these city names dynamically on my webpage in a list format. Can someone guide me through this process? If you w ...

Creating a CSS triangle that expands the full width of the page

Here is a triangle: #header-triangle-right { position: absolute; float: right; top:0px; right:0; z-index: 0; overflow: hidden; width: 0; height: 0; border-top: 400px solid transparent; border-right: 1000px solid #00 ...

Introducing a unique prefix to distinguish between two distinct product categories

Embarking on web design for the first time, I am currently in the process of creating a website for my Telephone Service and Signage Design company. Utilizing Wordpress to construct my site, with a woocommerce shop integrated, I am attempting to append dif ...

Run a Python function in Django without any feedback

Currently, I am utilizing Django for a project and I find myself in a situation where I need to carry out certain functions based on user input. If the action requires displaying new values, I know how to handle that. However, when I simply need to execute ...

Enhanced border appears when hovering over the element

Take a moment to visit the following website: Navigate to the Business Lines section and hover over Property Development & Project Management. Notice how the menu changes to double line when hovering. Is there a way to prevent this? I prefer to keep it ...

WP User Query and the wp-admin/admin-ajax function are both returning a value of 0, even with the

I have encountered a strange issue and I am seeking guidance to find a solution. Being new to PHP and JQuery, I am unsure of what is causing this problem. Essentially, I have an ajax call for a custom search field that functions properly. However, after ea ...

Encountering a 400 Bad Request Error with Salesforce LiveAgent Rest API

I've been working on a project that involves making a REST GET request to the salesforce Live Agent API to check service availability. While I've had success with making the simple GET request from my web-based REST client (using the Chrome Plug ...

Is it possible to save the information entered before exiting the checkout page?

Many of us have experienced this common frustration: When shopping online, we enter our checkout information, then want to double-check our items in the basket. After returning from the basket, all the fields we filled out are mysteriously empty. I beli ...

Is it possible to protect assets aside from JavaScript in Nodewebkit?

After coming across a post about securing the source code in a node-webkit desktop application on Stack Overflow, I began contemplating ways to safeguard my font files. Would using a snapshot approach, similar to the one mentioned in the post, be a viable ...

Retrieve the title and display it as a caption using JavaScript

Below is a snippet of code that takes the title from an element with the class a.preview, appends it to another element with the ID p#preview, and generates some AJAX content on hover. While the title is printing elsewhere, the variable c in this script ...

Understanding the purpose of the notched property in Material-UI

I am currently integrating Material-UI into a project and exploring their API. One thing that I find confusing is the notched property within the OutlineInput Component. <FormControl variant='outlined'> <OutlinedInput notched={false} ...

Enhance your content with stylish text additions

Can anyone help me with merging 2 pieces of text in React JS, where one part of the text has unique styling? Below is an example of the code: <div> <div> {'If you haven\'t received an email, please check your spam filte ...

Nav Dropdown Beyond Container Bounds

I'm working on implementing a flexbox navigation menu with dropdowns for certain items. However, I've encountered an issue where the dropdown lists are appearing to the right of the container on hover, rather than below it as expected for a typic ...

Implementing CSS and JavaScript files into the core of WordPress

I am trying to integrate bootstrap into my WordPress setup in a unique way. While I am familiar with adding scripts and styles to a theme, that is not the solution I am looking for. I have examined the core WordPress files and attempted to insert the boot ...

My goal is to create collapsible and expandable rows within this table

Discover the code snippet here, without pasting the entire content... As an illustration, let's utilize this example: <head> </head> <body> <table> <tr> <th></th> < ...

Issue with Jquery .scroll method not triggering display:none functionality

Styling Using CSS #acc-close-all, #to-top { position: relative; left: 951px; width: 29px; height: 42px; margin-bottom: 2px; display:none; } #acc-close-all a, #to-top a { position: absolute; float: right; display: block ...

Tips for eliminating dots from material icons CSS

Recently, I incorporated a stylesheet from Google's Material Icons into my web project. However, upon implementing the HTML code provided to display the icon, I encountered an unexpected issue - a dot appeared beside the icon, which I do not want to b ...

.flex-grow-1 in react-bootstrap does not expand to fill vertical space within <Row>

I'm having trouble using the .flex-grow-1 class in Bootstrap 4.6.0 (with react-bootstrap 1.5.2) to make a component within my layout expand and fill the remaining vertical space available. "bootstrap": "^4.6", "react-bootstrap ...