我有一个问题,将CSS应用于具有特定类的li元素。我想改变那个李的背景颜色,但我找不到一种方法来做到这一点。我不确定这是否会改变'父',因为我知道css无法控制父母。CSS将属性应用于具有特定类的li
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>
非常感谢你的建议,
非常感谢你的例子。有用。但是,我的代码怎么会只适用于信背景而不是李?请指教 – Till
这可能意味着还有其他干扰css风格,你可以检查'li'元素和共享样式 –