Transforming text color on hover: A quick guide

Is it possible to change the text color on hover of a <li> without hovering over the text itself?

For a demo, visit http://jsfiddle.net/EU4cz/

Here is the HTML code:

<nav id="NAv" >
<ul>
<li><a href="">Home</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Employment</a></li>
<li><a href="">Benefits</a></li>
<li><a href="">Forms</a></li> 
</ul>

And here is the CSS:

nav#NAv
{
  width:192px;
  background:#FFF;
  padding:0px;
}

nav#NAv a
{
  color:#18819c;
}

nav#NAv ul li
{ 
  height: 30px;
  width: 192px;
  margin: 5px 0px -5px -10px;
  padding: 5px 0px 0px 10px;
  border-bottom:2px solid #c9dce1;
}

nav#NAv ul li:hover 
{
  background:#0f7691; 
  color:#FFF;
}
nav#NAv ul li a:hover 
{
  color:#FFF;
}

Answer №1

Ensure that your nav#NAv a links have display:block; and height:100%; added:

nav#NAv a {
    color:#18819c;
    display:block;
    height:100%;
}

CodePen demonstration

Links are typically inline, but by converting them to block and setting the height, they will fill the space of the list item.

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

Set $scope.model childs to an empty string or a null value

While working on a form, I am using a $http request to send the information through Angular in the following manner: $http({ method:"POST", url: "controllers/servicerequest.php", data: { servicerequest: $scope. ...

Using Key Press to Rotate Messages - Jquery

Need help with rotating an array based on alphanumeric key presses? Check out the code snippet I've been working on below. Unfortunately, I'm having trouble getting the loop to function properly. Any suggestions or feedback would be greatly appre ...

Flawlessly Outputting PHP and HTML

When querying a result from a table, I face an issue where the text does not automatically wrap to a new line if it's too long. This results in the text being displayed on a single line and often extending off the page. How can I ensure that the text ...

Having trouble with the Image Path not connecting from the backend to the frontend of my application

I have been working on getting photos from my backend server and displaying them on my website. The images are stored in the API with a path that looks like localhost:44333/Images/[imagename]. On the frontend, I have tried adding the path dynamically, as ...

The beforeunload function in jQuery is not behaving as anticipated

My current goal is to show a pop-up with three choices whenever a user attempts to close the tab while on my website, and then store that choice somewhere. In my main.js file, which loads across all site pages, I have implemented the following code: $(do ...

Is it possible to export a table to a CSV file using jQuery/JavaScript code, no matter how large the table is? Check out the jsfiddle link for

Check out this link to view the table and code: http://jsfiddle.net/KPEGU/485/ I am experiencing an issue with exporting the table to Excel CSV. When I click the export button, a blank CSV file is generated without any data. // The following JavaScript ...

File transfer locally using jQuery AJAX GET was successful, however, the data was found to be undefined

Trying to test jQuery AJAX, I wrote a simple code in a local HTML file, shown below: $(document).ready(function(){ $.ajax({ url: "http://hqdigi2.eastmoney.com/EM_Quote2010NumericApplication/CompatiblePage.aspx?Type=Z2&r=1386912455181&fav ...

Styling the topbar with CSS includes adding a vertical separator that neatly wraps the content within the

I recently created a website using HTML and CSS, featuring a topbar. However, I encountered an issue while trying to insert a vertical separator between some of the icons within the topbar. Initially, when I added the separator-div, only the first three ic ...

A dynamic 2-column website design featuring a mobile-friendly layout and an adaptable image

After searching through numerous resources on the topic, I have yet to find a solution to this particular challenge. Is it feasible to create a webpage layout with a text column on the left and an image column on the right that will seamlessly transition i ...

Guide on triggering an open modal when clicking a link using jQuery

Creating a modal popup has always been my goal. After designing the CSS to style it, I found myself stuck as I lack knowledge in JQuery or JavaScript to code the functionality that animates and opens the modal upon clicking a button or link. Despite search ...

Is there a way to retrieve the ID by using the autocomplete feature to search for a user's first name and last name in PHP

Check out this code from index.php (all credit to the original owner): <HTML> <HEAD> <TITLE> Ajax php Auto Suggest </TITLE> <link href="css/style.css" rel="stylesheet" type="text/css"> <SCRIPT LANGUAGE="JavaScript ...

retrieve the option text based on the value selected in the combobox

Similar Question: jQuery get select option text Assuming I already have the value of the dropdown, even without making a selection, I want to know how to create a selector that retrieves the text associated with that value. Here is the corresponding ...

designing icon buttons

I am interested in adding big buttons with icons to my website. I have images named largebut_hover.png, largebut.png, and icon.png. The icon image is supposed to be displayed inside the light grey background of largebut.png, and when hovering, it should sw ...

Perplexed by the Cufon hover issue

I am really frustrated right now because I can't seem to get Cufon working properly. I have a span link with text inside it, and I want the font color to change when hovered over. Cufon.replace('.info-grid a span', { fontFamily: 'Vegur ...

Managing the automatic download of a zip file through JQuery - A guide

When working with a REST API and creating a zip file for forced download, the task is to call the API by sending necessary POST data through JQuery to initiate the download. How can this goal be accomplished effectively? ...

Issue with displaying custom in-line buttons in JQGrid

Currently, I am utilizing jqgrid 3.8.2 (I am aware it's not the latest version, but I plan on updating it soon after seeking some advice :-)) I have successfully incorporated a couple of in-line buttons into my jqgrid using the default formatter &apo ...

What is the best way to eliminate the ' from every element in an array in this situation?

My form has hidden fields with values enclosed in single quotes like 'enable'. Using jQuery, I extract these values and push them into an array. This array is then sent to a PHP file using JavaScript through the url attribute of the jQuery AJAX m ...

Switch between various components using multiple buttons in Next.js

I am in the process of creating a component that will display different components depending on which button the user selects. Here are the available “pages”: ` const navigation = [ { name: "EOQ", return: "<EOQgraph />" }, { nam ...

Custom pagination page size in AngularJS trNgGrid

I have been working on developing an Angular table using trNgGrid. It's functioning fine, but I am looking to incorporate custom pagination where the user can choose the number of page items to display per page. I checked out the TrNgGrid Global Opti ...

Why is Typescript unable to recognize the name '$' even after importing jquery?

Currently, I am utilizing TypeScript version 1.4.1 for a project setup like this: scripts/ libs/ jquery/ jquery.d.ts // Latest from DefinitelyTyped jquery.js // 2.1.3 lodash/ lodash.d.ts // Latest fr ...