I have several hierarchies separately listed out below where first selector is the parent div, second is the image item within the div. But could I combine these somehow?
.outdoors .how-to-image {
cursor: pointer;
}
.snowsports .how-to-image {
cursor: pointer;
}
.stripe .how-to-image {
cursor: pointer;
}
.twilio .how-to-image {
cursor: pointer;
}
.rental_requests .how-to-image {
cursor: pointer;
}
This selector is used to select every element which is not the first-child of its parent element. It is represented as an argument in the form of :not(first-child) element. Explanation: The above example shows that a <div> is a container Tag.
There is currently no way to select the parent of an element in CSS in a way that works across all browsers. That said, the Selectors Level 4 Working Draft includes a :has() pseudo-class that will provide this capability. It will be similar to the jQuery implementation.
The element>element selector is used to select elements with a specific parent. Note: Elements that are not directly a child of the specified parent, are not selected.
:not(:last-child) Combining these two above selector to excludes the last children (inner-div) of every parent div from the selection.
If the parent element doesn't matter, then you could simply use:
.how-to-image {
cursor: pointer;
}
Otherwise, you would have to combine the selectors. The simplest form would be:
.outdoors .how-to-image,
.snowsports .how-to-image,
.stripe .how-to-image,
.twilio .how-to-image,
.rental_requests .how-to-image {
cursor: pointer;
}
Aside from that, there is no other way to simplify it. Even if you were to use LESS, the same would be outputted.
.outdoors, .snowsports, .stripe, .twilio, .rental_requests {
.how-to-image {
cursor: pointer;
}
}
Output:
.outdoors .how-to-image,
.snowsports .how-to-image,
.stripe .how-to-image,
.twilio .how-to-image,
.rental_requests .how-to-image {
cursor: pointer;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With