Is a selector like *+* safe to use?
Posted
by
mcmullins
on Stack Overflow
See other posts from Stack Overflow
or by mcmullins
Published on 2012-02-14T20:17:30Z
Indexed on
2012/09/01
15:38 UTC
Read the original article
Hit count: 159
css
|css-selectors
I recently came across this CSS selector while trying to find a way to easily space out major blog elements such as paragraphs and images. An example of its use would be something like this:
.post *+* {margin-top: 15px;}
/* or... */
.post > *+* {margin-top: 15px;}
/* if you don't want the margin to apply to nested elements */
At first glance, it seemed pretty useful. So my question is: What downsides are there to using these selectors?
Specifically:
What's the browser support like for this?
Are there any cases you wouldn't want an even margin spacing between elements in an article and if not, is it easier to declare this first and then overwrite or simply declare each element individually?
Does this have performance issues since you're selecting everything twice?
© Stack Overflow or respective owner