CSS将属性应用于具有特定类的li

时间:2013-01-22 06:36:44

标签: html css

我有一个问题是将css应用于具有特定类的li元素。我想改变那个li的背景颜色,但我找不到办法做到这一点。我不确定这是否正在改变'父母',因为我知道css无法控制父母。

CSS

.navi ul li { padding:20px; background-color: #00; }


.navi ul li + .current_location { background-color: #FFF; }

or

.navi ul li .current_location { background-color: #FFF; }

//will only change the background color of letters inside, no the li element.

current_location + ul li { background-color: #FFF; }

// will only apply to the children of the li which has class .current_location.



I want to change the li background color where it has class .current_location;

HTML

   <nav class="navi">
            <ul>
              <li>
                <a>General Config</a>
              </li>
              <li class="current_location">
                <a>Menu</a>
              </li>
              <li>
                <a>User Level</a>
              </li>
              <li>
                <a>User</a>
              </li>
              <li>
                <a>Tag</a>
              </li>
              <li>
                <a>Log</a>
              </li>
            </ul>
          </nav>

非常感谢你的建议

3 个答案:

答案 0 :(得分:3)

.navi ul li + .current_location应为.navi ul li.current_location

Fiddle

+选择器用于在元素后选择next元素 例如:div+p将选择p元素之后的所有div元素。 example

答案 1 :(得分:1)

删除 .current_location &amp;之间的空格。的 LI 即可。写得像这样:

.navi ul li.current_location { background-color: #FFF; }

答案 2 :(得分:1)

.navi ul li.current_location {background-color:#FFFFFF; }

相关问题