如何在css中以不同的方式给出前两个段落的相同样式.
<html>
<head>
<style type="text/css" media="screen">
p+p {color:red}
</style>
</head>
<body>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
<p>fourth paragraph</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这个,但是它会留下第一段和其他所有样式.
而这种风格第一款不是别人的
<html>
<head>
<style type="text/css" media="screen">
p:first-child { color: blue; }
</style>
</head>
<body>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
<p>fourth paragraph</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
记得我想在前2段给出相同的风格.
去这里,试试这个代码:)
http://www.w3schools.com/css/tryit.asp?filename=trycss_first-child1
p:first-child
{
color:blue;
}
p:first-child + p
{
color: red;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3884 次 |
| 最近记录: |