我必须将边距设置为 <p>
根据选择器中的 child(h1) 元素跟随选择器。像这样:
selector:not(>h1) + p
{
margin: 10px 0 0 0;
}
HTML:
<a><h1>test</h1></a>
<p>test</p>
<a>
是我的选择器,只有当 a 包含 <h1>
时,它(或后面的 p)才应该有边距。 .不可能将边距设置为 h1。
这没有用:有没有办法在纯 CSS 中做到这一点? 我认为这是 CSS3 选择器中缺少的东西。
最佳答案
如果不使用 jQuery ':has' 绝对没有办法让你的选择器工作,在那种情况下,我会写这个查询:
$('selector > p:not(selector > p:has(h1))');
如果嵌套函数甚至可以在 jQuery 中工作
CSS 不能工作的原因是因为没有:has 功能,并且:contain 被贬低了。
关于css - 为什么 :not(>h1) not possible? 在纯 CSS 中有任何解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9364912/