Trouble with hover functionality on nested HTML table rows is not functioning correctly

I am having an issue with a nested table in my code. I do not want the child table to have hover effects and zebra striping, but despite my efforts, it is still displaying those styles. Below is my code:

<table class='zebrastrip'>
    <tr>
        <td>1</td>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
    <tr>
        <table class='atable'>
            <tr>
                <td>5</td>
                <td>6</td>
            </tr>
            <tr>
                <td>7</td>
                <td>8</td>
            </tr>
        </table>
    </tr>
</table>

<style>
    .atable tr:nth-child(2n-1){
        background-color: #FFFFFF;
    }
    .atable tr:hover{
        background-color: #FFFFFF;
    }
    .zebrastrip tr:nth-child(2n-1){
        background-color: #f9f9f9;
    }
    .zebrastrip tr:hover{
        background-color: #fce4cc;
    }
</style>

Any help or guidance on this issue would be greatly appreciated. Thank you!

Answer №1

check out the revised code snippet: http://jsfiddle.net/aBcDe/

Revised HTML:

<table class='striped'>
   <tr>
    <td>A</td>
    <td>B</td>
   </tr>
   <tr>
     <td>C</td>
     <td>D</td>
   </tr>
   <tr>
      <td colspan="2">
          <table class='inner-table'>
            <tr>
              <td>E</td>
              <td>F</td>
            </tr>
            <tr>
              <td>G</td>
              <td>H</td>
            </tr>
          </table>
      </td>
  </tr>
</table>

Updated CSS to ensure inner table background is always white:

increased specificity for inner table styles

defined background color for inner table

.striped tr:nth-child(2n-1){
    background-color:#f9f9f9;
}
.striped tr:hover{
    background-color:#fce4cc;
}
.striped .inner-table{
    background: #FFFFFF;
}
.striped .inner-table tr:nth-child(2n-1){
    background-color:#FFFFFF;
}
.striped .inner-table tr:hover{
    background-color:#FFFFFF;
}

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

Display only a section of a webpage

Currently in the works is a C# windows application where I am utilizing a WebBrowser control to showcase a web page. My objective is to manage the visible area of the WebBrowser so that only a specific region of the web page is displayed. Here is how the ...

Unable to fix position: sticky issue following Angular 15 update

Following the angular material update to version 15, many of us experienced issues with CSS changes breaking. This also affected legacy code that included sticky headers. <div class="row"> <div class="col-12"> <di ...

Dynamic arrangement of a dual-column table design that avoids aligning tables in parallel

Apologies for my novice coding skills as it's a mishmash of various email layouts, but I'm struggling to figure out why my table layout is not showing the columned tables side-by-side. The issue seems to be with the two td elements having the cl ...

My web application has defaulted to using compatibility mode for IE5 for browser compatibility

Our .NET web application starts with an index.asp, which includes numerous iframes loading different HTML files. The compatibility mode for our web application should be set to IE8. The problem we are encountering is that when we open the app in Internet ...

What is the best way to remove bootstrap when transitioning to a new microfrontend?

Our team is facing an issue with styling when using a combination of React, Bootstrap, and Tailwind. The problem arises when linking our micro frontend to modules that use Tailwind, as the Bootstrap styles persist despite the change. Since both Tailwind an ...

Resolving CSS Fluid Image Problem

Even though my site background is responsive and functions well, I am encountering problems with the images. I want them to appear "fixed" in the same position as the background, regardless of resolution changes. For example, resizing the browser from 990p ...

Knitting: exporting to HTML file while retaining formatting

Recently discovered the amazing knitr library in R, which looks great when viewed in the viewer. But unfortunately, the style gets lost when saved to an html file. Code library(knitr) library(kableExtra) some.table <- data.frame ( x = rep(1 ...

Steps for making a hyperlink functional from a database

Currently on my website, I have implemented a 'save to favorites' button which allows users to save recipes to their favorites and view them on their dashboard. While I have successfully displayed the favorites on the dashboard with hyperlinks, I ...

Ensure that the radio button and its corresponding label are aligned on the same horizontal line

When dealing with multiple radio buttons, each paired with a label, how can you ensure that the button and label always stay on the same line, while also automatically shifting to the next line for the next pair? For example, on a large screen: () Label ...

Retrieve the Element from the Shadow DOM or leverage the main site's styles

I am currently involved in a project that utilizes Polymer (still on version 1.7, but we are planning to switch to a different technology instead of upgrading). My task involves exploring ways to integrate DynamicYield, a personalization platform that inse ...

Navigating with AngularJS

My server is utilizing angular for routing purposes. It sends a HTML file containing a js file with routing using angular js to the browser. Here is the server code (which sends the check.html with the routing file main.js) : var express = require("expre ...

Verification checkbox in Html5 is mandatory

I have created an input checkbox that contains array values, resulting in multiple rows being generated in a table. However, the issue I am facing is that all checkboxes need to be checked in order to submit the form. This means I cannot submit the form un ...

Sliding the cursor downward to unveil a panel? (utilizing MooTools)

I'm looking to implement a feature where a DIV panel slides in when the user clicks and drags a smaller tab. While there are tutorials available for sliding elements on click, I specifically need the panel to slide in only when the user interacts with ...

Disabling the "disabled" property on input buttons using CSS overrides jQuery's capabilities

Recently, I updated the CSS style for an input button on my website. However, after making these changes, the prop('disabled',true) function no longer works as expected (it had worked perfectly before the CSS modifications). Here is the HTML cod ...

Ways to update the CSS classes of a bootstrap navigation menu

I am working with a bootstrap navigation bar that includes an option called "Add New Candidate" as a list item. I need to update its class from "nav-item has-treeview" to "nav-item has-treeview menu-open" when the user selects it, and also change the class ...

Hierarchy of importance when multiple style rules affect an element

When an element in HTML has multiple style rules applying to it, what is the precedence order? The rules that apply to an element identified by its unique id come first Next are the rules applied to all elements of a specific class Lastly are the rules th ...

Generating a dropdown menu using JavaScript from a JSON data source

I'm having trouble figuring out how to approach this task. What I want to do is generate multiple select inputs dynamically, each with different options but sharing a common set of choices. Let's say I have the following data in a JSON file: da ...

Personalize a bootstrap theme specifically for the mobile interface

My current template, based on Bootstrap, displays a text along with a button and an image. Using a checkbox, you can choose whether the image appears to the right or left of the text. One issue I'm facing is that in the mobile view, the text and butt ...

Arranging the alignment of list item text with CSS/HTML

Consider this HTML snippet: <ul><li><p>With paragraph</p></li></ul> <ul><li>Without paragraph</li></ul> and the corresponding CSS: ul { list-style-position: inside; } In the first list item, t ...

Tap the mobile menu button twice to toggle the menu

Incorporating: Visual Studio 2013, ASP.NET (VB) Webforms. Upgrading an existing WebForms website from .NET 2.0 to .NET 4.5 and implementing mobile-friendly features for better Google support. I have added a button to the top right corner as follows: < ...