Among the varieties of CSS selectors, one particular that is often overlooked is the CSS Adjacent Selector.
Adjacent sibling selectors have the following syntax: E1 + E2, exactly where E2 is the topic of the selector. The selector matches if E1 and E2 reveal the identical parent from the document tree and E1 right away precedes E2.
The CSS code
h4 + p font-weight: bold; color: #000;
The text beneath is actually a easy example with the over code:
This is typical heading 4 text
This may be the <p> after the heading. It should be daring and black.
What’s even better is that this seems to work perfectly in IE 7 (UPDATE: it seems that this does not work in IE6, so it will likely be a bit before that is usable on any large scale. However, it is still good to understand these obscure CSS selectors because you may come across them as a professional,
Office 2010 Sale, especially if IE8 successfully puts IE6 out of the top 5 browsers), Firefox,
Window 7 Custom Written Essay.html, Opera, and Safari. Now I know what you’re thinking. Wherever from the world am I going to use this?
Perhaps we could use something like this to do something to all rows in a table except the first row? What if we knew the next element after an <img> tag was going to be considered a custom caption that we wanted to place properly underneath our image? The only problem I see is that this couples the HTML and CSS more than we might like sometimes. However, there are many places that probably would benefit from something this straightforward. Simplicity rules. Now that you know how to use it I have every confidence you can come up with a brilliant use for it.
What ideas do you have to use this CSS gem? What other selectors have you found useful but don’t often see?