CSS selector for image captions I have this CSS selector:

.img + *{
}


Which, from my understanding, will make the browser look for all the elements and then select only those which follow an element with the class img. Is there a better way of writing this selection to improve performance?

Relevant HTML structure:

&lt;div class="media"&gt;
    &lt;div class="img"&gt;
        &lt;img src="an-image.jpg"&gt;
    &lt;/div&gt;
    &lt;random-element&gt;content is here&lt;/random-element&gt;
&lt;/div&gt;
My recommendation would be to not worry about the performance (see: http://www.kendoui.com/blogs/teamblog/posts/12-09-28/css_tip_star_selector_not_that_bad.aspx for actual tests).

If you're still not convinced that it's not as bad as everyone makes it out to be, then your only real option is to modify the contents of &lt;random-element /&gt;.

&lt;div class="media"&gt;
    &lt;div class="img"&gt;
        &lt;img src="an-image.jpg"&gt;
    &lt;/div&gt;
    &lt;random-element&gt;&lt;div id="foo"&gt;content is here&lt;/div&gt;&lt;/random-element&gt;
&lt;/div&gt;


Which allows your CSS to be:

.img + #foo { ... }


Or just

#foo { ... }