html - 将父 css 规则应用于子项

标签 html css sass

使用 SCSS,我想将 .parent 中的 disabled 样式应用于其子项。

我当前的 SCSS 结构是这样的:

.parent {
   .disabled {
     background: grey;
   }
   > .group {
      ...
      > .input {
          background: white;
        }
      > .icon {
          background: blue;
        }
   }
}

HTML:

<div class="parent" ng-class="{disabled: el.isDisabled}">
   <div class="group">
      ...
      <textarea class="form-control input">
         ...
      </textarea>
      <div class="icon">
         ...
      </div>
   </div>
</div>

如何将这些样式应用于inputicon


对于上下文,我目前拥有的是相当多余的:

.parent {
   > .group {
      ...
      > .input {
           background: white;
           &.disabled {
              background: grey;
           }
        }
      > .icon {
           background: blue;
           &.disabled {
              background: grey;
           }
        }
   }
}

最佳答案

只需将您的类嵌套在禁用类中:

   .parent.disabled {
     > .group {
       ...
       > .icon,
       > .input {
         background: grey;
       }
     }
   }

关于html - 将父 css 规则应用于子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43722318/

相关文章:

javascript - 防止 AngularJS 中跨路由的字段输入重复

css - 如何在 ie6 上不显示 css 投影?

html - 纯文本单选按钮

css - 当其容器/父元素悬停时将 css 样式应用于元素 Angular

css - 1 个 sass block 中的多个标签

javascript - html5 中的 2D 侧滚动相机 View

html - 在一行的中心(同一行)显示两个图像,但中间有一个特定的空间

jquery - Bootstrap 日期选择器 Z-index safari

css - 如何获取 Sass 或 CSS 中最后分配的属性的值?

javascript - JS 中的 HTML 连接问题