Styling of individual rows on hover in HTML

Here is the table I am working with:

<tr>
       <th><p>ID</p></th>
       <th><p>NAME</p></th>
       <th><p>CLASS</p></th>
       <th><p>EDIT</p></th>
       <th><p>DELETE</p></th>
</tr>

Below is the code from my css file:

table.mytable tr{
 background-color: #ffff99;
}

I am facing an issue where row highlighting on hover is not working for me. Can someone please help me figure out what went wrong?

Thank you, Viswa

Answer №1

Utilize the :hover selector to change color upon hovering:

table.mytable tr:hover{
 background-color: #ffff99;
}
<table class="mytable">
<tr>
       <th><p>ID</p></th>
       <th><p>NAME</p></th>
       <th><p>CLASS</p></th>
       <th><p>EDIT</p></th>
       <th><p>DELETE</p></th>
</tr>
<tr>
       <td>1</td>
       <td>ABC</td>
       <td>2</td>
       <td>edit</td>
       <td>delete</td>
</tr>
</table>

Answer №3

check out this suggestion:

TO CHANGE hover color, add P:hover selector:

p:hover{
 background-color: #ffff99;
}

Thank you

VIEW DEMO HERE

ALTERNATIVELY

.mytable{
        width:100%; 
        border-collapse:collapse; 

    border:#4e95f4 1px solid;
    }
    .mytable td{ 
        padding:7px; 
    border:#4e95f4 1px solid;
    }

    .mytable tr{
        background: #b8d1f3;
    }

    .mytable tr:hover {
          background-color: #ffff99;
    }

UPDATED DEMO AVAILABLE HERE

Answer №4

Hello.

If you want to make text stand out when you hover over it, be sure to include the necessary css code for hover effects. Since your content is enclosed in <p> tags, you can easily achieve this by adding the following lines to your css stylesheet.

p:hover{
  background-color: #ffffcc;
}

Ensure that there are no spaces between the colon and the word 'hover'.

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 automatically navigating pages using HTML

My dilemma involves two HTML pages: flash.html main.html I am seeking a solution where the flash.html page is loaded first for 5 seconds, after which the main.html page should automatically load. How can I achieve this? I attempted to use setTimeout(fu ...

What is the best way to connect the state of a variable from one class to another in React?

How can I utilize the variable "restaurants" in Editar2.js? ---App.js--- const { restaurantes } = this.state; ---Editar2.js--- const ChooseRestaurant = (props) => { const options = props.restaurants.map((option) => { return(<opt ...

Avoiding the repetition of CSS animations during Gatsby page hydration

I am facing an issue in Gatsby where I have an element with an initial CSS animation. It works perfectly when the static site loads, but after hydration, it keeps repeating. Is there a way to prevent this from happening? Below is my styled components code ...

Updating the global CSS styles that were inherited from the node_modules folder in a Next.js project

I've been attempting to customize the CSS style for a rc-pagination component that was included in a CSS file I already imported in the root component _App. However, despite my efforts to override the styles in the index.css file of this component, no ...

Tips for hiding a div only on mobile devices while always displaying it on large screens using AngularJS or CSS

How can I use Angularjs or css to hide a div on mobile devices only, ensuring that it is always displayed on large screens? ...

Django and Pure CSS are used to create a unique radial timer

After successfully creating a 5-minute radial timer using pure CSS, I've begun my journey with Django. I'm eager to explore whether I can take this timer to the next level and make it functional for all users who visit my page. Is it possible for ...

Designing a webpage layout with DIV elements that span across multiple rows

I am attempting to create a layout that features two columns, with the right column spanning two rows. I am looking to accomplish this using only DIV tags: +-----------+-----------+ + + + + + + +-----------+ ...

Looking to create a toggle button to show more or show less dynamic API data in a React component?

I have a specific requirement for my web page where I have multiple tabs, each of which displays dynamic data obtained from an API. The data is constantly changing on a daily basis. Within each tab, there is a rectangular box with a fixed height, and below ...

How can I eliminate unnecessary gaps in a CSS slider design?

Currently, I am in the process of learning CSS3 and attempting to create a purely CSS slider. Everything has been going smoothly until I encountered an unexpected padding or margin within my slider. After making some adjustments to the margins, the issue ...

Is there a way to decrease the size of the content within this iFrame?

Is there a way to display 6 cameras on a single webpage without them taking up the entire screen within iframe windows? Can the content be shrunken to fit the iframe window? <!doctype html> <html> <head> <meta charset="utf-8"> &l ...

Detecting a click event within a hidden div located behind another visible div

I am facing an issue with triggering ng-click in a div that is covered by another div. The current scenario I have is as follows: https://i.sstatic.net/SfM5y.jpg Basically, I need to activate ng-click on the yellow circle when it is clicked. However, the ...

Unforeseen outcomes discovered by stacking one div over another, all without relying on z-index

My current project involves two stacked divs, each measuring 100px by 100px. The bottom div includes a black border on top, as shown in this example. <div id="top"></div> <div id="bottom"></div>​ div { width: 100px; height ...

What is the correct way to effectively target nested elements using CSS?

For a while now, I've been creating websites using HTML and CSS, carefully matching specific tags to my classes or IDs. However, I recently noticed a trend where people use selectors like #test > #blah to indicate that #blah is nested inside of #te ...

SVG path with dynamic elements

Consider the following SVG: <svg xmlns="http://www.w3.org/2000/svg" width="237" height="129" viewBox="0 0 237 129" fill="none"> <path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.4 ...

Circular picture contained within a Bootstrap column on an irregularly-shaped image file

I am looking to create a circular effect for an image that is originally rectangular, resembling a typical profile picture. I have come across several sources on how to do this. The challenge arises in trying to achieve this effect within a bootstrap colu ...

Animate div visibility with CSS transitions and Javascript

I'm currently working on incorporating an animation into a div that I am toggling between showing and hiding with a button click. While I have the desired animation, I am unsure of how to trigger it using JavaScript when the button is clicked. Can any ...

Is it possible for Websockets to receive data from Ajax requests?

I am currently working on creating a PHP and HTML5 websocket chat system. In this setup, one end will be a socket while the other end will be AJAX. Is it possible for PHP's socket_recv() function to receive data from sources like AJAX, MySQL, or any o ...

Two different background colors adorn the Table and Body, adding a touch of visual

Hi everyone, I have a basic question regarding the styling of a webpage. I want the body of the page to have one color while having the table in the center with a different color. I've tried specifying different colors for the body and table in CSS, b ...

Is it feasible to swap out the cursor for a personalized image of my choice?

Can I replace the cursor icon with my own custom image that I created in Photoshop? I have seen websites with custom cursor images, so I know it is possible. But how do I do it and is it a standard approach? Will it work across all browsers? ...

Increase the gap between two bootstrap columns on smaller screens when viewed in col-xs-12

Is there a way to address the issue where the two columns in property of col-xs-12 are displayed without any gap when the browser is resized to a mobile-sized screen? Any guidance on how to fix this would be greatly appreciated. View in large size View in ...