CSS to target every second visible tr element using the :nth-child(2n)

My table has a unique appearance (shown below) thanks to the application of CSS nth-child(2n).

tr:nth-child(2n) {background-color: #f0f3f5;}

https://i.sstatic.net/1AnDi.png

I made some elements hidden on the vID, ID, and MO_Sub tr.

<tr style="display:none">

The table's new look is displayed below, with background color changes for "MO" and "MODEL".

https://i.sstatic.net/aotEM.png

I tried something like the code below but it didn't have the desired effect.

tr:not(.isotope-hidden):nth-child(2n)

If anyone has ideas on how to apply CSS after hiding certain tr elements, I would appreciate any help!

EDIT: additional snippet provided

tr:not([style*="display:none"]):nth-child(2n){
    background-color: #f0f3f5;
}

tr:hover{

    background-color: cadetblue;

}
 <table id="form_tb">
                    <tr style="display:none">
                        <td><label>vvID :</label></td>
                        <td><input type="text" name="vvID" placeholder="vvID" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>vID :</label></td>
                        <td><input type="text" name="vID" placeholder="vID" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>vID_sub :</label></td>
                        <td><input type="text" name="vID_sub" placeholder="vID_sub" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>ST :</label></td>
                        <td><input type="text" name="Station" placeholder="Station" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>SortID :</label></td>
                        <td><input type="text" name="SortID" placeholder="SortID" readonly></td>
                    </tr>
                    <tr>
                        <td><label>MO :</label></td>
                        <td data-key='MO'><input id=MO type="text" name="MO" placeholder="MO" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>MO_Sub :</label></td>
                        <td><input type="text" name="MO_Sub" placeholder="MO_Sub" readonly></td>
                    </tr>
                    <tr>
                        <td><label>PART :</label></td>
                        <td data-key='text'><input type="text" name="Part_number" placeholder="PART" readonly></td>
                    </tr>
                    <tr>
                        <td><label>MODEL :</label></td>
                        <td><input type="text" name="Model" placeholder="MODEL" readonly></td>
                    </tr>
                    <tr style="display:none">
                        <td><label>Class :</label></td>
                        <td><input type="text" name="Product_Class" placeholder="Class" readonly></td>
                    </tr>
                    <tr>
                        <td><label>Side :</label></td>
                        <td><input type="text" name="Side" placeholder="Side" readonly></td>
                    </tr>
                    
                </table>

This should be the final result based on the snippet shared.

https://i.sstatic.net/vayVn.png

Answer №1

The selector for the nth child only applies to children that are specifically the nth child of their parent element. In this scenario, it targets table.children[n] when n is an even number. Interestingly, it does not correspond to the even values of the filtered outcomes.

To address the issue with :hover, one potential solution could be adding :not(:hover) to the initial CSS selector, although this may not resolve all aspects of the problem.

I came across this question and another one found at this link, both discussing similar matters.

In some cases, utilizing JavaScript might offer a more effective approach.

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

Optimized layout for screen resolutions exceeding 1000 pixels wide

As I work on making my website responsive using Dreamweaver CC, I'm encountering a problem with screen sizes larger than 1000px. In Dreamweaver, there are three options for responsive web design at the bottom: desktop 1000px and less, tablet 768px an ...

unable to assign the disable property to a button element

In the code snippet below, I am working on a child-component. I have created a button and I want to include a disable property. However, the current implementation of the code results in an error message with red underlining indicating: Type '"is ...

The resend email feature isn't functioning properly on the production environment with next js, however, it works seamlessly in the development environment

import { EmailTemplate } from "@/components/email-template"; import { Resend } from "resend"; const resend = new Resend("myApiKey"); // this works only in dev // const resend = new Resend(process.env.NEXT_PUBLIC_RESEND_API_KE ...

Certain iFrame instances are unable to display specific cross-domain pages

I'm currently working on a project to create a website that can embed external cross-domain sites, essentially like building a browser within a browser. I've been experimenting with using iFrames for this purpose: While it works for some pages, ...

What are the steps to customize the format of Vue3 Datepicker extensions?

Is there anyone who can lend a hand? I am currently using the Vue3 Datepicker and I have received a value that looks like this Thu Jun 23 2022 17:14:00 GMT+0700 (Western Indonesia Time) Does anyone know how to transform it into the following format? Thu, ...

What is the mechanism behind the functioning of a click event within a leaflet bindpopup?

I am trying to incorporate a button inside the leaflet popup that will zoom in to the location of the point when clicked. The button and its corresponding event are defined within the pointToLayer() function. However, upon clicking the button, there is no ...

Is there a reason we are able to simultaneously assign the disabled and selected attributes to <option> elements?

What is the rationale behind permitting the simultaneous setting of disabled and selected attributes on <option> elements, knowing that their values will not be submitted to a server? I was surprised that I did not receive an error in VS Code when I ...

The functionality of Express' render/redirect is limited to being triggered only by a submit method within a form

Objective To execute a POST request through a JavaScript method in order to send variable values as parameters. Setup NodeJS Express BodyParser ejs Initial Approach Frontend: <html> <head> <script src='http://ajax.go ...

Save mathematical equations written in HTML text boxes to a MySQL database

How can I display mathematical formulas in a text input and store them in a database? I need to be able to display formulas like the ones shown in the image at this link: Currently, when I copy any formula into the text box, it gets converted to normal t ...

Transform the checkbox selection into an active hyperlink upon being selected

Currently, I am in the process of designing a form that allows visitors to select items they would like to view by checking relevant checkboxes. Upon clicking a Request button, the URLs of the selected items are displayed. I aim to have the URL appear as ...

Encountered an error during the production build of NEXTJS, where it panicked due to the global thread pool not being initialized

While hosting my app on Heroku and running git push heroku main, I encountered the following error: panicked at 'the global thread pool has not been initialized.: threadpool builderror { kind: ioerror(error { kind: unsupported, message: "operatio ...

Creating numerous hash codes from a single data flow using Crypto in Node.js

Currently, I am developing a Node.js application where the readable stream from a child process' output is being piped into a writable stream from a Crypto module to generate four hash values (md5, sha1, sha256, and sha512). However, the challenge ari ...

Applying unique textures to individual sides in Three.js

Here is the code for my textured cube: const textureLoader: TextureLoader = new TextureLoader(); const textureArray: MeshBasicMaterial[] = [ new MeshBasicMaterial({ map: textureLoader.load("./model/front.jpeg") }), new MeshBasicMaterial({ map ...

Tips for passing a variable from one function to another file in Node.js

Struggling to transfer a value from a function in test1.js to a variable in test2.js. Both files, test.js and test2.js, are involved but the communication seems to be failing. ...

Tips on how to decorate a radio button using borders and colors

How can I change the color of my radio button and its border color? I attempted to modify the code below, but it is not producing the desired result. li.payment_method_bacs input[type='radio']:checked:before { background: black !important ...

jQuery fade in problem or alternate solutions

When I send a post request to a file and input the response into id='balance', I would like it to have a flickering effect or fadeIn animation to alert the user that it is being updated in real time. I attempted to use the fadeIn() method but it ...

Storing Canvas Jquery data in an ASP.NET C# database

I need assistance with saving canvas (signatures) created using Asp.Net webforms and JQuery into a SQL server database. Can anyone provide suggestions on how I can achieve this? What type of field should I use to store it in the database? ...

Tailored design - Personalize interlocking elements

I am currently working on a custom theme and I am trying to adjust the font size of Menu items. In order to achieve this, I have identified the following elements in the tree: ul (MuiMenu-list) MuiListItem-root MuiListItemText-root If I want to modify th ...

Attempting to execute code on a database using PHP and MySQL

Hey there! I am just diving into the world of HTML and PHP, attempting to create a page that can execute an SQL query to transfer data from one table to another. However, I'm facing some difficulties in making it work as I need a user-provided date t ...

Mysterious data organization - transform into an object

As I interact with an API, there is a value that I cannot quite pinpoint. My goal is to transform this string into a JavaScript object, but the process seems complex and confusing. Does anyone have insight on what this data represents and how it can be co ...