css - 定位 h2::after 包含 h2::before

标签 css pseudo-element

如何将一些CSS专门应用于h2::after,并且还有一个h2::before?

.region-sidebar-second .block > h2::after, .region-content .block > h2:after {
  content: "";
  display: block;
  width: 30px;
  margin-bottom: 1.25rem;
  margin-top: 0.75rem;
  border: 0.5px solid #252525;
  position: relative;
}

#block-block-51 h2::before{
  padding-right: 5px;
  content: "\f02d";
  font-family: "Font Awesome 5 Pro",sans-serif;
  font-weight: 900;
}

::after_selector_for_those_h2_that_have_a_::before{
   left:2rem;
}

最佳答案

你不能,至少现在还不能。这需要一个选择器来选择具有 before 伪元素的元素,而该伪元素并不存在。选择器仅适用于 DOM 中可用的内容。

有一个工作草案可以通过pseudo-class selector :has()来实现这一点。 。它看起来如下:

element:has(::before)::after

但是,从文档来看:

In the current specification :has is not marked as part of the live selector profile, which means it can not be used within stylesheets; only with functions like document.querySelector().

关于css - 定位 h2::after 包含 h2::before,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59422809/

相关文章:

css - 在vue.js组件中,如何在css中使用props?

javascript - jQuery 多处理范围 slider 空闲到处理程序

javascript - 更改 :before or :after CSS 中的 SVG 填充颜色

html - 在伪元素周围包装 header 和 p

javascript - 使用javascript点击伪元素?

javascript - jQuery:从 HTML 页面获取所有链接,除非该链接属于特定类或 ID

css - 适合空白空间的 child 高度

javascript - 来自另一个页面的正文加载中的ajax弹出中心

css - 使用 jQuery 与 CSS3 :after 并行设置属性上的标题

html - 如何让CSS伪元素的区域可以点击?