html - CSS中下一个元素的选择器的语法是什么?

标签 html css css-selectors siblings

如果我有一个标题标签 <h1 class="hc-reform">title</h1>

h1.hc-reform{
    float:left;
    font-size:30px;
    color:#0e73bb;
    font-weight:bold;
    margin:10px 0px;
}

然后我有一段<p>stuff here</p> .

如何确保每个 <p> 使用 CSS h1.hc-reform 之后的标签使用:clear:both;

会是:

h1.hc-reform > p{
     clear:both;
}

由于某种原因,这不起作用。

最佳答案

这被称为 adjacent sibling选择器,用加号表示...

h1.hc-reform + p {
  clear:both;
}

注意:IE6 或更早版本不支持此功能。

关于html - CSS中下一个元素的选择器的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3660046/

相关文章:

javascript - 边框半径和 Javascript

html - 在不知道宽度的情况下,仅使用 css 以绝对位置居中 div

java - WebDriver 未检测到输入文本框,抛出 ElementNotInteractableException : element not interactable

css - 如何将此 css 重写为 xpath

javascript - 只有手机safari打不开页面,没有网络消息

javascript - JQuery 中的点击事件没有响应

html - visual studio 代码 - 如何评论 html 的多行(每行而不是整个 block )

html - 如何在 Tailwind CSS 中通过边距填充更改占位符位置?

Jquery选择器:not inside child div

css - 无效的 CSS 选择器导致规则被删除 : What is the rationale?