applying hover effect to text within a table

After investing some time into solving this issue, I am still struggling to find a solution. Essentially, what I want is for the :hover pseudo-class to trigger the border-bottom effect only when I hover over the text in a table.

Currently, the :hover pseudo-class activates when I hover within the table cell, but my aim is to have it activate specifically when hovering over the text.

Here is the link to my jsfiddle for reference:

http://jsfiddle.net/fbubU/1/

(Unfortunately, the border-bottom effect isn't highlighting in the jsfiddle preview)

Here are snippets of my code:

        <table id="navbar">
        <tr>
            <td class="nav1"></td>
            <td id="hover" class="nav2"><a href="http://www.google.com/">home</a></td>
            <td id="hover" class="nav2"><a href="http://www.google.com/">products</a></td>
            <td id="hover" class="nav2"><a href="http://www.google.com/">services</a></td>
            <td id="hover" class="nav2"><a href="http://www.google.com/">about</a></td>
            <td id="hover" class="nav2"><a href="http://www.google.com/">contact</a></td>
            <td class="nav1"></td>
        </tr>
    </table>


table#navbar {
border:3px solid black;
margin:0 auto;
border-collapse:collapse;
}

td.nav2 {
text-align:center;
width:100px;
font-size:20px;
font-weight:bold;
}

td.nav1 {
width:243px;
}

a:visited, a:link  {
color:black;
text-decoration:none;
}

td#hover:hover {
border-bottom:3px solid e8e8e8;
padding-bottom:1px;
}

I apologize if my question is unclear.

Edit: I have fixed the issue with the jsfiddle, thank you for all the responses!

Edit 2: I believe I have successfully achieved the desired functionality, thanks again for all the help.

Answer №2

Here's a simple solution:

The issue lies where you are specifying the bottom border color:

border-bottom:3px solid e8e8e8;

It should actually be:

border-bottom:3px solid #e8e8e8;

Now, for a more detailed explanation:

Your code has several other issues that may not be the cause of the error but should still be addressed. Consider using lists for navigation and make sure to use unique IDs for elements in your HTML.

Answer №3

There are a couple of issues to address here. Firstly, you have duplicated the same ID which is causing a problem. You should consider changing your selector to td.nav2 a:hover to make use of the class instead. Secondly, ensure that you include the '#' before the color code in your definition; omitting the hash may result in using a color by name (such as white, black, red, green, blue, etc).

The current CSS selector in place targets the entire <td>.

td.nav2 a:hover {
  border-bottom: 3px solid #e8e8e8;
  padding-bottom: 1px;
}

This will only trigger when the user hovers over the link.

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

An illustration of a skeleton alongside written content in neighboring sections

I am relatively new to CSS and came across an issue with Skeleton when resizing the browser window. I have an image and text displayed next to each other in columns, as shown below (although there is much more text in reality). Everything looks fine initia ...

Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far. Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it ...

Chrome is having trouble displaying Roboto font correctly

I have been experiencing an issue with the rendering of the Roboto font on a client's website. When I view the site in Chrome (version 43.0.2357.65 m), all the different weights of Roboto appear to look the same. For example, here is a comparison: On ...

Unusual dark streak beneath the Wordpress emblem

I recently created my website using Wordpress and decided to use a PNG image (140*82 px) as the logo instead of the default "site-title". However, I encountered an unusual issue where a black line appeared just below the image. After checking my "header.ph ...

Connect the checkbox input to the text input

I'm facing an issue where I need to tie a checkbox input to a text input in my form. Here's the scenario: I am extracting data from a database. The primary key data serves as the value for the checkboxes. When a checkbox is selected, it should ...

Design of website built on Bootstrap framework seems distorted on Firefox browser

I built this website with the help of Bootstrap and you can view it at js-projects. Everything looks great when I open it in Chrome or Safari, but there are weird white strips that resemble scroll bars when I view it in Firefox. Can someone assist me in ...

Tips for comparing two arrays and displaying matching elements in separate columns

I am faced with the challenge of working with two arrays. The first array contains a list of all dates, while the second array holds the dates when a person is present. My objective is to generate a table that displays all the dates in the first row, and ...

What is the best method to customize CSS in ExtJS 5.0 by overriding a function?

Is there a way to dynamically add a rule to existing CSS using code, particularly in overrides? For example: var sheets = document.styleSheets; // Some code omitted for simplicity var sheet = sheets[sheets.length - 1]; sheet.insertRule('.overlay {flo ...

Using single page anchor tags in Next.js to toggle content visibility

The Issue Currently working on a project using Next.js and facing a challenge: needing to hide or replace content based on the selected category without reloading the page or navigating to another route. Furthermore, ensuring that when the page is reloade ...

Tips for transferring information obtained from an API to my custom HTML page

As a novice in web development, I recently created a simple weather report website using the OpenWeather API. While I successfully fetched data from the API, I encountered an issue trying to display this data on my HTML page. Despite utilizing DOM manipu ...

Deliver acquired post information to HTML using the read file technique

I've been diving into the world of nodeJS, jquery-mobile, and HTML5. Below is a snippet of my code: Fetching post data from an html form: req.addListener("data", function(postDataChunk){ postData += postDataChunk; console.log("Received POST ...

Using jquery to update a link when a different link is clicked

Recently, I've started using JQuery and encountered a challenge. When I click on the first link, an Ajax request is sent to the server and data is received successfully. However, in the callback function, I'm struggling to change the display text ...

Understanding JavaScript Regular Expressions

To ensure that no HTML tags are entered into a textarea, I am utilizing the following regex for validation. If any HTML tags are detected in the textarea, I need to display a validation message. The regex being used is: /<(\w+)((?:\s+\w ...

Is there a smooth and effective method to implement a timeout restriction while loading a sluggish external file using JavaScript?

Incorporating content from an external PHP file on a different server using JavaScript can sometimes be problematic. There are instances where the other service may be slow to load or not load at all. Is there a method in JavaScript to attempt fetching th ...

Numerous attributes for displaying ngOption values

I have an item that resembles the following: $scope.team = [ { name: "John", number: 1 }, { name: "Emma", number: 2 } ]; Currently, in my HTML code, I am using ngOption to populate a dropdown menu with values from the object. < ...

Update the FontSize in the HTML dropdown menu using JavaScript

I am having trouble filling my Selection using a script. For example, when I try to populate my FontSizeMenu, I use the following code snippet: function FillFontSizeMenu() { FillSelection(GetPossibleFontSizes(), "fontSizeMenu"); } function GetPossib ...

Executing a JavaScript function across multiple elements: A step-by-step guide

I recently came across this code snippet on w3schools.com: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * {box-sizing: border-box} body {font-family: Verdana, ...

Angular index.html file can include a conditional script

I am currently working on an Angular project, where the index.html serves as the main entry point for the application, just like in any other Angular project. This file contains important links and configurations. Within the HTML code snippet below, you w ...

Ways to tackle my code's linked dropdown issue without the use of extensions

When I selected the Id Province, I couldn't select the Id City. How can I fix this issue? Controller code snippet to address this: View code snippet for the same: ...

What could be the reason my checkbox won't check using jQuery?

Currently, I am using kojs within my Magento 2 project. I have implemented a method that successfully shows and hides an input box based on user interaction. However, despite the function working as expected, the checkbox does not display its checkmark. D ...