首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

,怎么对许多段落单独设置各个样式

2013-06-25 
请教高手,如何对许多段落单独设置各个样式?大家好,我想问下,我有一段文字,有很多p我现在对第一个p 单

请教高手,如何对许多段落单独设置各个样式?
大家好,我想问下,我有一段文字,有很多<p>

我现在对第一个<p> 单独设置了class ,采用first-child 这种方法来对第一个<p>设置。

但是现在我想对第二个,或者剩余其他的所有段落设置样式,请问如何设置? 采用什么方法。

我想这样实现,第一个p 的样式为class1 , 其余的p 的样式全部为class2.

请问这里有人会吗?
[解决办法]

<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>无标题文档</title>

<style type="text/css">
p:first-child { background-color:#CCC}
p { background-color:#ABC}
</style>
</head>

<body>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
</body>
</html>

[解决办法]
<html>
<head>
<meta charset="gb2312">
<title>无标题文档</title>

<style type="text/css">
.p_detail { background-color:#CCC}
.p_excerpt { background-color:#ABC}
</style>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    $("p:first-child").addClass("p_detail")
    $("p:not(:first-child)").addClass("p_excerpt")
});
</script>

</head>
 
<body>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
</body>
</html>

热点排行