覆盖CSS中的先前背景

时间:2014-03-25 16:11:32

标签: html css

所以我遇到了问题,我认为可能缺乏对css规则的理解。希望你们能帮助我!

span.medback {
background-color: FFFFCC; 
}
span.hiback {
background-color: FF3333;
}
span.item1 {
display: block;
background-color:#DCF0F7;
width: 75px;
height: 58px;
border: 1px solid #000000;
float: left;
padding: 5px;
text-align: center;
}
span.item2 {
display: block;
background-color:#DCF0F7;
width: 70px;
height: 58px;
border: 1px solid #000000;
float: left;
padding: 5px;
text-align: center;
}
span.item3 {
display: block;
background-color:#DCF0F7;
width: 90px;
height: 58px;
border: 1px solid #000000;
float: left;
overflow: auto;
padding: 5px;
}
span.item4 {
display: block;
background-color:#DCF0F7;
width: 170px;
height:48px;
border: 1px solid #000000;
float: left;
overflow: auto;
padding: 10px;
}
span.item5 {
display: block;
background-color: #DCF0F7;
width: 80px;
height:58px;
border: 1px solid #000000;
float:left;
padding: 5px;
}
span.item6 {
display: block;
background-color: #DCF0F7;
width: 30px;
height: 58px;
border: 1px solid #000000;
float:left;
padding: 5px;
}

span.item6 a img {
width: 20px;
height: 20px;
}
span.item1 a img {
width: 20px;
height: 20px;
}

span.item7 {
display: block;
background-color: #DCF0F7;
width: 30px;
height: 58px;
border: 1px solid #000000;
float:left;
padding: 5px;
}

请原谅极长的CSS线 - 这是了解我的问题所必需的

<ul id="sortable" class="mainlist"><li class="listwrap" id="arrange_69"><span class="item1 "><a class="checkmarked" href=""><img src="" title="check" alt="check" /></a></span>
<span class="item2 ">&#x25B2; | &#x25BC;</span>
<span class="item3 ">monkey</span>
<span class="item4 "></span>
<span class="item5 "></span>
<span class="item6 "><a class="edit" href=""><img title="edit" alt="edit" src="" /></a></span>
<span class="item7 "><a class="confirm" href=""><img title="Delete" alt="Delete"src="" /></a></span></li>
<li class="listwrap" id="arrange_72"><span class="item1 hiback"><a class="checkmarked" href=""><img src="" title="check" alt="check" /></a></span>
<span class="item2 hiback">&#x25B2; | &#x25BC;</span>
<span class="item3 hiback">new</span>
<span class="item4 hiback"></span>
<span class="item5 hiback">Mar 25th 2014 12:30 PM</span>
<span class="item6 hiback"><a class="edit" href=""><img title="edit" alt="edit" src="" /></a></span>
<span class="item7 hiback"><a class="confirm" href=""><img title="Delete" alt="Delete"src="" /></a></span></li></ul>

我的问题是为什么第二个li中的hiback类不会覆盖其他元素的背景颜色?有没有办法可以获得这种功能? (重写整个事情是一个选项,如果它的设计很差)感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

由于:

  • 你的hiback类规则无效,你错过了颜色代码中的#
  • 选择器同样是specific
  • 当选择器具有同等特异性时,the last one gets applied last(覆盖之前的选择器)

答案 1 :(得分:1)

你的第一个问题是这些颜色应该有#个标志:

span.medback {
    background-color: #FFFFCC; 
}

span.hiback {
    background-color: #FF3333;
}

其次,你应该在定义项目类之后移动它们的定义。

小提琴:http://jsfiddle.net/ybJGw/