Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS 2, precedence of stylesheets imported using link element

Tags:

css

Given

<link rel="STYLESHEET" href="/css/t.cake.css" type="text/css"/>
<link rel="STYLESHEET" href="/css/f.css" type="text/css"/>
<link rel="STYLESHEET" href="/css/t.generic.css" type="text/css"/>
<link rel="STYLESHEET" href="/css/t.head.css" type="text/css"/>

which rules have a higher priority in the cascade? Assume all have equal priority wrt other CSS comparisons? Those in the first, or last stylesheet?

TIA DaveP

like image 387
DaveP Avatar asked Dec 06 '22 06:12

DaveP


1 Answers

According to the specs, the latest one is applied.

4. Finally, sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins. Declarations in imported style sheets are considered to be before any declarations in the style sheet itself.

Anyhow, would not be good practice to rely on this alone, as it makes your code hard to read and interpret. I would make sure the correct rules were applied through specificity of the selectors, no matter what stylesheet they are placed in.

like image 90
Arve Systad Avatar answered Jun 02 '23 00:06

Arve Systad