-2

Recently, I am studying CSS priority level of selector according to the page: https://www.w3.org/wiki/CSS/Training/Priority_level_of_selector, I have one problem:

* {
  margin: 0;
  padding: 0;
}
.see-me,
ul li {
  width: 300px;
  height: 300px;
  border: 1px solid red;
}
/* [0,0,0,2] */

ul li {
  background: yellow; color: red;
}
/* [0,0,10,0] */

.see-me {
  background: gray; color: blue;

}
<div class="see-me">
  <ul>
    <li>.see-me has higher priority level [0,0,10,0], so why is font color not blue, but red ?</li>
  </ul>
</div>

font color should be blue, but it is red ! here is DEMO

jian zhou
  • 113
  • 15

2 Answers2

1

The see-me class does in fact have a gray background. Since the ul element is a child of the div with the see-me class it is drawn on top of it.

  • but, if you put ul li { background: yellow; color: red; } and .see-me { background: gray; color: blue; } you will see, the font color also did not changed! – jian zhou Jul 13 '16 at 18:18
  • https://jsfiddle.net/8eeprjdf/2/ here is my update.. if so, is it not belongs to CSS priority level of selector ? – jian zhou Jul 13 '16 at 18:19
0

Because you couldn't see see-me!

* {
  margin: 0;
  padding: 0;
}
.see-me,
ul li {
  width: 100%;
  border: 1px solid red;
}
/* [0,0,0,2] */

ul li {
  background: yellow;
}
/* [0,0,10,0] */

.see-me {
  height:300px;
  background: gray;
}
<div class="see-me">
  <ul>
    <li>.see-me has higher priority level [0,0,10,0], so why is background not gray, but yellow ?</li>
  </ul>
</div>
brianxautumn
  • 1,162
  • 8
  • 21