这可能看起来很愚蠢..我想为某个 div
之后的 p
标签提供样式(div
不是p
标签的父标签)。例如
<div>Hai</div>
<p>Hello</p>
<p>How are you?</p>
在这里,我想为 p
标签赋予样式。我不能将这些 p
标签放在另一个 div
中。我想给所有 p
标签,然后是 div
相同的样式。而且我不能将样式普遍地赋予 p
标签,因为它会影响其他页面。谁能帮忙?希望我的问题很清楚...
最佳答案
您必须使用通用兄弟选择器:
div ~ p {
color: red;
}
请参阅此 jsFiddle:http://jsfiddle.net/yvdN6/4/ .
你可以看到 doc :
The elements don’t have to be adjacent siblings, but they have to have the same parent, and the
div
element has to occur before thep
element in the document source.
关于html - 设置 div 之后的 p 标签的样式(div 不是 p 的父级),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16791999/