notwaldorf / ama

:raising_hand: Ask @notwaldorf anything!
94 stars 13 forks source link

Are there any other places browser styles are defined besides the user agent stylesheet? #121

Closed faraixyz closed 4 years ago

faraixyz commented 4 years ago

Hi,

I first want to thank you for your article on how [hidden] is a lie which helped me fix a problem I was having.

Your article mentioned that the "rule is a User Agent style, which means it's less specific than a moderate sneeze" and the HTML spec says it can be implemented in CSS. I tried looking for a rule like [hidden] in the various browser default style sheets (Chrome, Webkit) and I couldn't find it.

Are some styles defined outside of this stylesheet?

Thanks again for writing the article, it really helped.

notwaldorf commented 4 years ago

This took some sherlocking! I know that for Chrome, for example, there are a bunch of other css files in that folder, such as quirks.css, but I couldn't find [hidden] in any of those!

At this point I was super curious, so I nerdsnipped @tabatkins, who said that based on what Elliott said in this comment, presentational hints aren't applied in the user stylesheet but instead they're manually applied here. Then they did more digging and found that it's set here, namely this gem:

if (name == html_names::kHiddenAttr) {
  AddPropertyToPresentationAttributeStyle(style, 
     CSSPropertyID::kDisplay, CSSValueID::kNone);
}

You can look into that file to find more styles that are set this way (just look for where else AddPropertyToPresentationAttributeStyle is called). Whew, mystery solved.

This was fun, thanks for asking this!!!