Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't combine selectors using commas in CSS

Tags:

html

css

HTML5 placeholders always appear slightly higher than the center of the input, so I'm trying to use CSS like ::-webkit-input-placeholder to push them down a bit. For some reason, I can't combine the selectors. Here's a Fiddle demonstrating this: http://jsfiddle.net/n7VV7/

I don't want to separate them because I use a CSS compression tool that automatically combines lines. Right now, I can manually separate them, but in the future, I will forget that I can't combine these lines.

like image 342
Leo Jiang Avatar asked Feb 17 '14 21:02

Leo Jiang


People also ask

Can you use commas in CSS?

A comma-separated list of selectors represents the union of all elements selected by each of the individual selectors in the list. (A comma is U+002C.) For example, in CSS when several selectors share the same declarations, they may be grouped into a comma-separated list.

What does comma in CSS selector mean?

The comma in a CSS selector separates multiple selectors within the same styles. For example, let's look at some CSS below. th { color: red; } td { color: red; }


2 Answers

You can't use commas to combine vendor-prefixed selectors because when a browser encounters a selector it does not understand, that line is "thrown out." This is why it's necessary to break up vendor prefixes for any selector, not just the :: pseudo-classes.

Here's a link to a CSS-Tricks comment on the problem.

like image 198
Marcatectura Avatar answered Nov 15 '22 00:11

Marcatectura


It seems that it is impossible to combine them in one selector, because input-placeholder selectors are used only separately and it is described in a standard.

There is a similar question around: Why isn't it possible to combine vendor-specific pseudo-elements/classes into one rule set?

like image 31
Maksim Gladkov Avatar answered Nov 14 '22 23:11

Maksim Gladkov