Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Add custom pseudo-classes

Discussion in 'UI Toolkit' started by DarkRewar, May 5, 2023.

  1. DarkRewar

    DarkRewar

    Joined:
    Jan 19, 2015
    Posts:
    18
    Hello,

    I'm trying to allow UXML integrators to easily create table where odd rows have different color than even rows. In CSS, something like this would work :

    Code (JavaScript):
    1.  
    2. table tr:nth-child(even) {
    3.   background: blue;
    4. }
    5.  
    6. table tr:nth-child(odd) {
    7.   background: #f8f8f8;
    8. }
    9.  
    But `:nth-child` does not seem to exist in USS yet following the official documentation Unity - Manual: Pseudo-classes (unity3d.com)

    I've seen there is an internal class `StyleSelector` which would do that, but it is inaccessible.

    How can I add my own pseudo-classes then and expose them in USS like in CSS?
     
  2. Kuuo

    Kuuo

    Joined:
    Jan 24, 2017
    Posts:
    8
  3. DarkRewar

    DarkRewar

    Joined:
    Jan 19, 2015
    Posts:
    18