css - 替代/深/

标签 css angular angular6 ng-bootstrap

我想更改 ng bootstrap 分页组件的样式并在 Angular 6 应用程序中使用 /deep/ 链接。以下代码工作正常,但控制台显示警告,指出该代码已被弃用。

那么,我应该如何更改它以消除警告?

这是我目前使用的 CSS 代码:

ngb-pagination /deep/ .page-item.disabled .page-link{
    background: none;
  }

 ngb-pagination /deep/ .page-item.active .page-link {
    background-color: #223C61;
    &:focus, &:visited{
      outline: none;
      box-shadow: none;
    }
  }

最佳答案

使用 /deep/::ng-deep 的替代方法是禁用 View Encapsulation在使用第三方 UI 元素的组件上。

@Component({
  selector: 'app-mycomp',
  templateUrl: './mycomp.component.html',
  styleUrls: ['./mycomp.component.scss'],
  encapsulation: ViewEncapsulation.None
})

这样做意味着:

Angular adds the CSS to the global styles. The scoping rules, isolations, and protections discussed earlier don't apply. This is essentially the same as pasting the component's styles into the HTML.

如果您关闭 View 封装,请确保只定位您真正需要的 html 元素,而不是您应用的不同组件中任何其他相同类型的元素(例如添加自定义 id 到您的元素)。

当我禁用 ViewEncapsulation 时,我还必须在我的 CSS 中使用 !important 来覆盖现有的第三方样式,而 并不总是需要它: :ng-deep.

关于css - 替代/深/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51708972/

相关文章:

angular - 即使我正确安装了 primeNG,为什么 PrimeNG 按钮类也无法工作?

javascript - 在 Angular 2 路由器中使用子状态会引发错误

angular - 隐藏特定路线上的标题 - Angular 6

Angular 6路由器链接问题在同一页面

Angular `ng update @angular/...` 返回 `401 Unauthorized`

css - 使用 Bootstrap 4 时,如何在大屏幕尺寸下定位(向下对齐)我的页脚?

html - 带边框半径的直 css 插入阴影

css - 重复背景图片有问题

html - 选中时的 CSS 样式单选输入

angular - Ng2-smart-table:是否可以显示和隐藏列?