Is this even possible?
<div class="column">
<div>
<div>
</div>
<div> <!-- Definitely not this DIV! -->
</div>
</div>
<div> <!-- THIS DIV ONLY! -->
</div>
</div>
The following CSS selector gets the one I've marked "Definitely not this DIV!".
.column div:last-child {
background-color:red;
}
The following CSS selector gets the one I want AND the one I've marked "Definitely not this DIV!".
.column div + div {
background-color:red;
}
Same goes for this one: It gets the one I want AND the one I've marked "Definitely not this DIV!".
.column div:first-child + div {
background-color:red;
}
Question: Is this even possible to do with CSS that will be recognized by IE7? (I assume my solution will work with FF, Safari, Chrome, and X:nth-child(n) only works with IE9+) Thanks.
Selecting Only the Next Sibling with Adjacent Sibling Combinator ( + ) The + character used in CSS is a combinator — it combines 2 CSS selectors. It selects the second element, only if it is just after the first element, and both elements are children of the same parent.
You have a list of elements inside a parent element and you want to select the second element only, for some reason, using only CSS. How will do that? Its simple. You can use the CSS :nth-child selector to select a particular element or the nth element, inside its parent element.
By using the :not(:first-child) selector, you remove that problem. You can use this selector on every HTML element. Another common use case is if you use an unordered list <ul> for your menu.
The CSS id Selector The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
This should do it.
#column > div:first-child + div
You were using a class selector to select an element with an ID.
You may want to look through the CSS Selectors, as it's the direct descendant & sibling selectors that gives you the finesse to choose a particular DOM element.
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