W3cubDocs

/GTK 4.0

Selectors

Selectors work very similar to the way they do on the web.

All widgets have one or more CSS nodes with element names and style classes. When style classes are used in selectors, they have to be prefixed with a period. Widget names can be used in selectors like IDs. When used in a selector, widget names must be prefixed with a # character.

GTK CSS Selectors

Pattern Reference Notes
* CSS Selector Level 3
E CSS Selector Level 3
E.class CSS Selector Level 3
E#id CSS Selector Level 3
E:nth-child(n) CSS Selector Level 3
E:nth-last-child(n) CSS Selector Level 3
E:first-child CSS Selector Level 3
E:last-child CSS Selector Level 3
E:only-child CSS Selector Level 3
E:link, E:visited CSS Selector Level 3 Corresponds to GTK_STATE_FLAG_LINK and GTK_STATE_FLAGS_VISITED
E:active, E:hover, E:focus CSS Selector Level 3 Correspond to GTK_STATE_FLAG_ACTIVE, GTK_STATE_FLAG_PRELIGHT, GTK_STATE_FLAGS_FOCUSED
E:focus-within CSS Selector Level 4 Set on all ancestors of the focus widget, unlike CSS
E:focus-visible CSS Selector Level 4 Set on focus widget and all ancestors, unlike CSS
E:disabled CSS Selector Level 3 Corresponds to GTK_STATE_FLAG_INSENSITIVE
E:disabled CSS Selector Level 3 Corresponds to GTK_STATE_FLAG_CHECKED
E:indeterminate CSS Selector Level 3 Corresponds to GTK_STATE_FLAG_INCONSISTENT
E:backdrop, E:selected Corresponds to GTK_STATE_FLAG_BACKDROP, GTK_STATE_FLAG_SELECTED
E:not(selector) CSS Selector Level 3
E:dir(ltr), E:dir(rtl) CSS Selector Level 4
E:drop(active) CSS Selector Level 4
E F CSS Selector Level 3
E > F CSS Selector Level 3
E ~ F CSS Selector Level 3
E + F CSS Selector Level 3

© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/ch38s02.html