Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winning CSS color attribute doesn't match with result

I'm seeing a strange scenario where, according to the Firefox dev console, the matched color for a css element is different from the visible output. If it matters, I'm using Bootstrap 3 as the source of styling. Here is the (very short) HTML file that I'm using for the example.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

<button class="form-control btn btn-success">Hello world</button>

Here is a screenshot from the Firefox dev console with the purported 'winning' css rule for: enter image description here

And here is a screenshot of the actual browser rendering: enter image description here

As you can see, the text in the button is rendered as white. From the top of the CSS rules, it appears that white was, indeed, selected. But it's not clear where that comes from. The only rule say "it's white (#FFF)" is crossed out, and the only rule that's not crossed out says "it's dark grey (#555)". So why is the text white?

like image 295
J-bob Avatar asked Jul 02 '15 20:07

J-bob


People also ask

How do I fix color in CSS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

Which property is used to set colors in HTML?

The color property is used to set the color of the text. The color is specified by: a color name - like "red" a HEX value - like "#ff0000"

Which one of the following is acceptable way of specifying color in CSS?

The most common way to specify colors in CSS is to use their hexadecimal (or hex) values. Hex values are actually just a different way to represent RGB values. Instead of using three numbers between 0 and 255, you use six hexadecimal numbers.

Which component of Colour property represents the transparency of a Colour?

The alpha component specifies the transparency of the color: 0 is fully transparent, and 255 is fully opaque. Likewise, an A value of 255 represents an opaque color.


1 Answers

Interesting observation! It would appear that the Firefox developer tools use the line number of the declaration block to determine selector importance, when the specificity of two selectors is the same.

This can be an issue when the CSS file is minified though, and all declaration blocks end up on the same line.

It becomes more apparent if you use the non-minified resource:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">

A JSFiddle with the minified CSS exhibits this problem, but not one using the fully expanded CSS.

Hope this sheds some light on the issue. Maybe it's worth a bug report?

EDIT: A bit more testing indicates that the Firefox tools places precedence on the left-most block when faced with multiple same-specificity selectors on a single line. (An example.)

like image 161
Serlite Avatar answered Oct 14 '22 14:10

Serlite