我有一个如下的html
<!DOCTYPE html>
<html>
<head>
<style>
p{font-size:14pt;color:red;}
</style>
</head>
<body>
<div>
<p> this is a p without class defined</p>
</div>
<div class = "temp">
<p> this is a p tag in another div</p>
</div>
<div class = "test">
<p> this is a Original Mail</p>
<p class="hello"> this is a p tag </p>
<p> this is a p without class defined</p>
<div> this is a div tag
<p> this is a p tag within the div</p>
</div>
</div>
</body>
</html>
我想将样式应用到带有类测试的 div 中的所有 p 标签。
我试过像 div.test > p{font-size:14pt;color:red;} 但是随后该样式未应用于具有类名测试的 div 的子 div 中的 p 标记。 请帮我解决这个问题。
最佳答案
JSFiddle:http://jsfiddle.net/8K2yL/
你想要的选择器是:
div.test p {
font-size:14pt;
color:red;
}
这将选择 div.test
标签内任意位置的所有 p
标签。
选择器 div.test > p
只会选择 p
标签,它们是 div.test
的直接子标签。
关于css - 将样式应用于元素中的所有子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364673/