If I wanted to do a CSS selector on a list like this:
<ul>
<li></li>
<li><a></a></li>
<li><a></a></li>
<li><a></a></li>
</ul>
and I wanted to do a li:hover
effect on only the li
s that contain an <a>
tag, is there a way to specify that in CSS? if li:hover contains <a> then li:hover effect = X?
The :nth-child(n) selector matches every element that is the nth child of its parent. n can be a number, a keyword (odd or even), or a formula (like an + b). Tip: Look at the :nth-of-type() selector to select the element that is the nth child, of the same type (tag name), of its parent.
The element > element selector selects those elements which are the children of the specific parent. The operand on the left side of > is the parent and the operand on the right is the children element. Example: Match all <p> element that are child of only <div> element.
The CSS class Selector The class selector selects HTML elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the class name.
The CSS ID selector matches an element based on the value of the element's id attribute. In order for the element to be selected, its id attribute must match exactly the value given in the selector.
No, CSS does not allow you to select elements based on their descendants.
You can do it in JQUERY:
$("a").parent("li").css("color","#923123");
For what you requested, it would be like this:
$("li").mouseover(function(){
if ($(this).is(':parent'))
{
//this <li> has a child, supposed to be <a>
}
});
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