The structure of my HTML is like so
<div>
<div>
<h1>Something</h1>
</div>
<div>
<h1 class='Handle'>Something</h1>
</div>
</div>
In the event that the div > div
does not have a child with the class "Handle" I want the the div > div
to have the style cursor:move;
. How would I go about doing this in pure CSS, is it even possible?
The :empty CSS pseudo-class represents any element that has no children.
In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.
class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.
The [attribute^="value"] selector is used to select elements with the specified attribute, whose value starts with the specified value. The following example selects all elements with a class attribute value that starts with "top": Note: The value does not have to be a whole word!
This would work, except no browser currently supports it as far as I am aware. jQuery does though, however.
div > div:not(:has(h1.Handle)) {
cursor: move;
}
There is no parent selector in CSS, so what you are asking is not possible. What you can do is put the cursor:move
on every h1 that doesnt has the class "Handle" by using the attribute selector.
h1:not([class=Handle]) {
cursor:move;
}
http://jsfiddle.net/4HLGF/
Another option is to adjust your HTML, and move your h1 on the same level as the div.
<div>
<h1>Something</h1>
<div>
dragable content
</div>
<h1 class='Handle'>Something</h1>
<div>
non dragable content
</div>
</div>
Now you can do the same check on the h1, and target the div that comes after it.
h1:not([class=Handle]) + div {
cursor:move;
}
http://jsfiddle.net/4HLGF/2/
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