css - 子元素焦点状态更改父元素样式 SASS @at-root

标签 css sass accessibility

当下面代码中的子元素 span.icon-hamburger 收到 :focus 状态时,我想更改 li 元素的样式。使用 SASS 解决方案,我了解到 @at-root 可以在这里工作。但是,我无法使用 @at-root 为这个用例找到 SASS 解决方案。您对此用例有何看法?

HTML:

<ol>
  <li>
    <span class="icon-hamburger"></span>
  </li>
</ol>

CSS/SASS:

.icon-hamburger:focus {
  @at-root ol li #{&} {
    background-color: #fff;
  }
}

最佳答案

没有针对 IE 和 Edge 的解决方案,但对于 Chrome 和 Firefox,您可以使用 :focus-within CSS 伪类。

The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. (This includes descendants in shadow trees.)

https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within

关于css - 子元素焦点状态更改父元素样式 SASS @at-root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40183570/

相关文章:

css - 如何使用内联样式更改最后一个子项

javascript - 如何在用户滚动到它们之前加载 onScroll 背景图像?

twitter-bootstrap - 如何使用 variable.scss 在 Bootstrap 中更改主按钮的颜色?

android - 使用对讲辅助功能模式在滑动时阅读 viewpager 中的 fragment 内容

iphone - 滑动到另一个元素时 UIAccessibilityAnnouncementDidFinishNotification 不触发

android - 如何指定android自定义颜色资源: day/night/high contrast

jquery - -webkit-transition/-moz-transition 与 jQuery

javascript - 如果元素不适合 flex 布局,如何隐藏它?

html - 编辑 django 表单的表单 css

css - 使用类名和 React 看不到我的类?