Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could `currentBackgroundColor` become a valid, useful CSS color value keyword?

Tags:

css

css-color

CSS3 defines currentColor as a color equivalent to an element’s color property. It’s sorta kinda like a CSS variable, but on a per-element basis. When currentColor is used as a color value in any CSS property, it computes to whatever is the color value for the element to which it is applied.

So, my question is not whether something currentBackgroundColor exists—I have combed through the CSS3 Color specification and am fairly confident it does not—but whether it could exist.

Borrowing from the currentColor definition, I presume currentBackgroundColor would be defined as something like:

The value of the ‘background-color’ property. The computed value of the ‘currentBackgroundColor’ keyword is the computed value of the ‘background-color’ property. If the ‘currentBackgroundColor’ keyword is set on the ‘background-color’ property itself, it is treated as ‘background-color: inherit’.

Can anyone point to any implementation issues which I may not be considering?

like image 784
Jacob Ford Avatar asked Sep 18 '16 19:09

Jacob Ford


People also ask

What are valid CSS colors?

The W3C HTML and CSS standards have listed only 16 valid color names: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.

What is the valid attribute to set the background Colour in CSS?

With CSS, a color is most often specified by: a valid color name - like "red" a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)"

What is CSS color value?

The value in the CSS color property can be expressed as a hexadecimal value, rgb value, or as a named color. Color values can be expressed in hexadecimal values such as #FFFFFF, #000000, and #FF0000. Color values can be expressed using rgb such as rgb(255,255,255), rgb(0,0,0), and rgb(255,0,0).

Is transparent a valid CSS color?

A <color> can be defined in any of the following ways: Using a keyword (such as blue or transparent ). All existing keywords specify a color in the sRGB color space.


2 Answers

Can anyone point to any implementation issues which I may not be considering?

Yes. There could be circular dependencies:

* {
  background-color: current-color;
  color: current-background-color;
}

Moreover, currentcolor can be useful because text has a single color. But backgrounds usually have additional things like background-images and such. Lots of people only set a background image without caring about a fallback background color, which remains transparent. And then current-background-color is not much useful.

like image 153
Oriol Avatar answered Oct 24 '22 12:10

Oriol


Yes it could. For example, it would make it very easy to create an section of your text inverted-colour, ie you could swap the foreground and background colours to highlight something.

However, suggesting this as a CSS feature would be fighting against the tide. There used to be a whole bunch of CSS colour keywords, for things like the scrollbar colour, and the standard button colour, and the colours of the 3D shadows on the buttons... but they were all dropped from CSS some time ago.

There are lots of things in CSS that could be useful that aren't in there. Personally I'm more excited about CSS variables. When they become mainstream we are unlikely to be too worried about colour keywords like this

like image 25
Spudley Avatar answered Oct 24 '22 12:10

Spudley