0
<link rel="stylesheet" href="css/css.css">
<link rel="stylesheet" href="css/css2.css">

imagine in the first stylesheet is says h1 color blue. Imagine the second stylesheet says h1 color red. Which one wins?

tonitone
  • 54
  • 6
  • did you try it? you could have just test it locally. – ROOT May 20 '20 at 17:03
  • Does this answer your question? [Css style priority](https://stackoverflow.com/questions/12088007/css-style-priority) – h3t1 May 20 '20 at 18:08
  • You're right could've just tried it. The second stylesheet overrules. Would delete question but it advises against it. – tonitone May 20 '20 at 18:23

2 Answers2

0

there exists an order for style sheets according to their priority

Browser Defaults
External Style Sheets (Linked or Imported)
Internal Style Sheets (Embedded)
Inline Styles

In any of the methods, if the same style names are used, the last priority is higher than all the same names

kamal
  • 330
  • 3
  • 13
-1

I'm actually not sure, what happens if two css have the same name. I would assume it doesn't matter.

What does matter for sure is the order of css files. Files, which are included later have a higher priority in case of same selectors. So yes, the second one would win.

More important is even the selector. If a selector is more specific than another one, the more specific wins. E.g. body h1 is more specific than h1 and would win - even if included before the h1.

The only way to go around that, is to find either a more specific selector - or the same specific selector if included later - or to use !important.

Paul
  • 2,086
  • 1
  • 8
  • 16