I have div tag containing several ul tags.
If I trying set CSS properties only for the first ul tag, and this code works:
div ul:first-child {
background-color: #900;
}
When I want set CSS properties for each ul tag except the first, I tried this:
div ul:not:first-child {
background-color: #900;
}
also this:
div ul:not(:first-child) {
background-color: #900;
}
and this:
div ul:first-child:after {
background-color: #900;
}
But to no effect. How must I write in CSS: "each element, except the first"?
One of the versions you posted actually works for all modern browsers (where CSS selectors level 3 are supported):
If you need to support legacy browsers, or if you are hindered by the
:notselector’s limitation (it only accepts a simple selector as an argument) then you can use another technique:Define a rule that has greater scope than what you intend and then “revoke” it conditionally, limiting its scope to what you do intend:
When limiting the scope use the default value for each CSS attribute that you are setting.