2010-04-18 27 views
2

我在页面的内容中有几个p标签。我想在保存它们的div之前更改最后一个的颜色。我可以用CSS来做到这一点吗?我可以仅使用CSS更改最后一个p的样式吗?

<div class="text"> 
    <p>P One</p> 
    <p>P Two</p> 
    <p>P Three</p> 
    <p>P Four (this is the one I'd like to modify)</p> 
</div> 

感谢

回答

3

最简单的,可移植的方式:

<p class="last">P Four (this is the one I'd like to modify)</p> 

.text p.last {} 

的方便,便携更低的方式使用:last-child

.text p:last-child {} 

或者:last-of-type

.text p:last-of-type {} 
+3

这是':last-child'的支持图表:http://reference.sitepoint.com/css/pseudoclass-lastchild – 2010-04-18 07:34:32

+0

谢谢Roger!我将使用第二个示例,因为我正在动态加载文本 – Luli 2010-04-18 07:47:27

相关问题