我有一個問題,將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'元素和共享樣式 –