Html <ul>列表更改某些列表文本颜色和背景颜色</ul>

时间:2013-03-14 21:12:29

标签: css html-lists

我的HTML:

<ul class="tech">
  <li>JavaScript</li>
  <li>HTML / CSS</li>
  <li>PHP + MYSQL</li>
  <li>C#</li>
  <li class="software">PhotoShop</li>
  <li class="software">Brackets</li>
  <li class="software">Notepad++</li>
  <li class="software">Sony Vegas</li>
  <li class="software">eBay BlackThorne Pro</li>
  <li class="software">Senuke XCr</li>
  <li class="software2">X-Cart</li>
  <li class="software2">EKM PowerShop</li>
  <li class="software2">WordPress</li>
  <li class="software2">phpBB</li>
</ul>
</div>

这个html的Css部分:

.tech ul {
    padding: 0px 0px 0px 0px;
    margin-bottom: 10px;
    margin-top: 10px;
    list-style:none;
    list-style-position:outside;
}
.tech li{
  display:inline-block;
  text-align: center;
  background-color: #cccccc;
  color: #222222;
  margin: 5px 0px 5px 0px;

  border-radius: 3px;
  -moz-border-radius: 3px;
  box-shadow: 2px 3px 5px #000000;
  border: #969696 1px dashed;
}

.sofware {
    background-color:#646464;
    color: #ff7225;
}

.sofware2 {
    background-color:#4d4d4d;
    color: #fd205e; 
}

问题:列出软件和sofware2 ID不会改变颜色的项目。有什么问题?应该是这样的东西,我想我应该用“UL Li:n-child”设置这些颜色,但我不知道该怎么做。

先谢谢

2 个答案:

答案 0 :(得分:3)

jsfiddle说它有效:http://jsfiddle.net/nLWAE/1/

<ul class="tech">
  <li>JavaScript</li>
  <li>HTML / CSS</li>
  <li>PHP + MYSQL</li>
  <li>C#</li>
  <li class="software">PhotoShop</li>
  <li class="software">Brackets</li>
  <li class="software">Notepad++</li>
  <li class="software">Sony Vegas</li>
  <li class="software">eBay BlackThorne Pro</li>
  <li class="software">Senuke XCr</li>
  <li class="software2">X-Cart</li>
  <li class="software2">EKM PowerShop</li>
  <li class="software2">WordPress</li>
  <li class="software2">phpBB</li>
</ul>

.tech ul {
    padding: 0px 0px 0px 0px;
    margin-bottom: 10px;
    margin-top: 10px;
    list-style:none;
    list-style-position:outside;
}
.tech li{
  display:inline-block;
  text-align: center;
  background-color: #cccccc;
  color: #222222;
  margin: 5px 0px 5px 0px;

  border-radius: 3px;
  -moz-border-radius: 3px;
  box-shadow: 2px 3px 5px #000000;
  border: #969696 1px dashed;
}
.software {
    background-color:#646464;
    color: #ff7225;
}

.software2 {
    background-color:#4d4d4d;
    color: #fd205e; 
}

答案 1 :(得分:2)

首先,您的CSS选择器与您的id不匹配。您在id中有“软件”,但在CSS选择器中有“sofware”。但是你也有重复的id s,这是错误的。

更改您的

<li id="software"></li>
<li id="software2"></li>

<li class="software"></li>
<li class="software2"></li>

然后将您的CSS更改为:

.tech li.software {
    background-color:#646464;
    color: #ff7225;
}

.tech li.software2 {
    background-color:#4d4d4d;
    color: #fd205e; 
}