【问题标题】:Angular2 ng-content scss nested styles and StyleUrls not working when using :hostAngular2 ng-content scss嵌套样式和StyleUrls在使用:host时不起作用
【发布时间】:2016-11-08 03:00:54
【问题描述】:

我正在构建一个使用 ng-content 的组件,但我发现当我使用 :host >>> 时无法使用嵌套 scss 或 StylesUrl

例如:

:host >>> .toolbar-brand{
  color: red;
  font-weight: 500;
  text-decoration: none;
  font-size: 16px;
  text-transform: uppercase;
}

:host >>> .nav-bar-menu-options.hlink, .nav-bar-menu-options.drop-down{
  font-weight: 500;
  text-decoration: none;
  position: relative;
  top: -6px;
  font-size: 16px;
  text-transform: uppercase;
  padding: 0 10px 0 10px;

  &.has-divider {
    border-right: 1px solid #b0bec5;
  }

}

:host >>> .nav-bar-menu-options.hlink:hover {
  text-decoration: underline;
  cursor: pointer;
}
:host >>> .fill-remaining-space {
  flex: 1 1 auto;
}
:host >>> .search-link {
  cursor: pointer;
}

:host >>>.search-input-container{
  position:relative;

  .search-link{
    position: absolute;
    top: 3px;
    left:30px;
  }
}

:host >>> .my-input{
  border-left: 1px solid #b0bec5;
  padding: 11px 75px 11px 60px;
  background: transparent;
  outline:none;
  margin-left: 20px;
  width: 100%;
  &::placeholder {

  }
}

谁能告诉我为什么我的.has-divider 和我的嵌套.search-link 不起作用,以及为什么当我将内容放在.scss 文件中并使用styleUrls 时它不能与:host 一起使用.这是预期的还是可能的错误

理想情况下,我希望能够仍然使用来自和外部 scss 文件的嵌套 scss

【问题讨论】:

    标签: angular sass angular2-ngcontent


    【解决方案1】:

    >>> 已知会导致 SASS 出现问题。改用/deep/

    【讨论】:

    • so 这解决了从文件中读取而不是在行中读取的问题,但似乎仍然无法使用嵌套样式...
    • 实际上,如果我只是包裹在 :host /deep/ { ... } 中,它似乎可以按预期工作
    猜你喜欢
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2011-09-16
    • 2014-02-27
    • 2017-11-18
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多