2014-07-16 22 views
1

我有我的網站的導航欄下方貼:如何將CSS應用於特定菜單窗口中的塊元素?

enter image description here

每當活動菜單選項或者是主頁,關於,或聯繫人,導航欄是對齊完全爲你的不同選項之間進行選擇。

但是,當我在成員選項中時,導航欄稍微向左移動一點。我想將它向右移幾個像素,以便在導航過程中完美對齊。

我施加CSS以下塊元件:

.navigation > li > a 
{ 
    some styling 
} 

這會影響導航期間的導航欄的樣式。

但是,如何選擇會員時將一些邊距樣式應用於nav欄?

我可以重命名類名,但是我會重複代碼以重新設置nav欄,以及新添加的邊距修正。

是否有某種方式來檢查當成員是「活動」選擇,然後應用一些CSS保證金樣式?

+0

http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector –

+0

哦不對,我就可以在導航右父補充的嗎? – user1631224

+0

沒關係,沒有仔細閱讀 – user1631224

回答

0
<html> 
    <head> 
     <title>Parent selector</title> 
     <style> 
.left { 
    float: left; 
} 
.parent { 
    margin-left:20px; 
} 
.parent.marged{ 
    margin-left:40px; 
} 
.parent .child { 
    margin:10px; 
} 
     </style> 

    </head> 
    <body> 
     <div class="parent" id="parent"> 
      <div class="left child">Home</div> 
      <div class="left child selected" id="special">This Will Margin Parent</div> 
      <div class="left child">About</div> 
     </div> 
<script> 
var p = document.getElementById('parent'), 
    c = document.getElementById('special'); 
if (c.classList.contains('selected')) { 
    p.className += " marged"; 
} 
</script> 
    </body> 
</html> 
相關問題