2013-07-23 82 views
1

我工作的一個項目,但我無法找到一個方法來選擇儀表板選擇標籤的最後一個孩子

<div class="dashboard"> 
<div class="grid_6 alpha"> 
<div class="grid_6 omega"> 
<div class="grid_6 alpha"> 
<div class="grid_6 omega"> 
<div class="grid_6 alpha"> 
<div class="grid_6 omega"> //i wanna select this 
<div class="clear"></div> 
</div> 

我試過的最後孩子

.dashboard:last-child 
.omega:last-child 
+0

看這個SO搜索結果:http://stackoverflow.com/search?q=css+last+element,你的答案就在這裏:stackoverflow.com/questions/10415016/is-it-possible- to-target-the-very-last-list-element-in-css/10415207#10415066和google:https://www.google.ca/#gs_rn=21&gs_ri=psy-ab&cp=19&gs_id=cn&xhr=t&q=css +選擇器+最後+元素 –

+0

http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_nth-last-child –

+1

請考慮避免使用空標記進行造型。 – fcalderan

回答

6

的最後一個孩子是.clear,不.omega,所以.omega:last-child將不起作用。

如果該.clear將始終在那裏,請改爲使用.omega:nth-last-child(2)

如果你不能保證,那麼沒有一些腳本就不可行。

+0

非常感謝你這個作品 – synan54

0

我想你可以使用nth-child()選擇器。 鏈接:nth-child()

編輯:不能拼寫。

+0

這是拼寫nth-child,而不是n-thChild。 – BoltClock

+0

'n-child()'... – War10ck

0
<div> 
<span>John,</span> 
<span>Karl,</span> 
<span>Brandon,</span> 
<span>Sam</span> 
</div> 
<div> 
<span>Glen,</span> 
<span>Tane,</span> 
<span>Ralph,</span> 
<span>David</span> 
</div> 

<script> 
$("div span:last-child") 
.css({color:"red", fontSize:"80%"}) 
.hover(function() { 
     $(this).addClass("solast"); 
    }, function() { 
     $(this).removeClass("solast"); 
    }); 
</script>