1

Disclaimer: I know this is a bad idea and I'd never do it myself, but I'm trying to figure out what the CSS spec says.

If I have CSS like:

span { color: 'red'; color: 'green'; }

which one wins? The first one, the last one, a random one picked by my browser?

And related, if they're redundant but not equivalent, like:

span { border-top-width: 10px; border-width: 5px; }

does this parse exactly as if I'd said:

span { border-top-width: 10px; border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px; }

and then the previous rule applies? Or is there a different rule that applies with redundant-but-not-equivalent CSS properties like this?

I've been digging through the CSS spec and I can't seem to find anything that directly applies here.

thanks!

2 Answers2

3

It cascades to the last valid declaration. So - color:'green' would win.

Again, cascade wins. border-top-width would otherwise be styled independently, but border-width: would win to apply 5px to All.

Dawson
  • 7,567
  • 1
  • 26
  • 25
1

The last one always wins...

There are a few rules about priorities that everyone should know...

These are priorities that css follows:

  1. css propertie marked as "!important" -> always come first
  2. Inline code
  3. On page
  4. On external file

And then the last one declared on the file.

Best reference: CSS: Understanding the selector's priority / specificity

Another good one: http://www.hongkiat.com/blog/css-priority-level/

Hope it helps.

Community
  • 1
  • 1
Gabriel Augusto
  • 436
  • 4
  • 8