【问题标题】:Why styling is not applying to my elements?为什么样式不适用于我的元素?
【发布时间】:2020-04-20 20:41:20
【问题描述】:

我有一个 Angular 应用程序,其中有我的嵌套下拉菜单。在其中一个列表项中我有 primeng Tabview 在该列表项中像这样

<li *ngIf="user.role !== 'super'" class="nav-item flex-center-center flex-column min-width-40 no-border custom-bell-padding notifications-dropdown">
<a class="nav-link" id="notificationsDropDown" role="button" data-toggle="dropdown" aria-haspopup="true">
    <i class="fal fa-bell font-26"></i>
</a>
<div class="dropdown-menu" aria-labelledby="notificationsDropDown" (click)="onClick($event)">
    <span class="dropdown-menu-arrow"></span>
    <div class="ui-g header-dropdown-list">
        <div class="ui-g-12 list-item-border-bottom">
            <div class="ui-g-6">
                <p class="font-11 pb-0">Your Notifications</p>
            </div>
            <div class="ui-g-6 font-11 text-right">
                <app-checkbox [disabled]="disabled" label="Technician updates" [isChecked]="true"></app-checkbox>
            </div>
        </div>
        <div class="ui-g-12">
            <p-tabView class="tab-panel-underline">
                <p-tabPanel header="All">
                    <ng-template pTemplate="content">
                    </ng-template>
                </p-tabPanel>
                <p-tabPanel header="Critical">
                    <ng-template pTemplate="content">
                    </ng-template>
                </p-tabPanel>
            </p-tabView>
        </div>
    </div>
</div>

现在我正在像这样在component.scss 中应用自定义样式

.notifications-dropdown{
  .dropdown-menu {
   left: 843px !important;
   margin: -0.875rem 0 0;
   font-size: 0.875rem;
   color: #7A8281;
   text-align: left;
   list-style: none;
   border: 0 solid #c8ced3;
   box-shadow: 0px 3px 6px #00000029;
   z-index: 99999;
   top: 74px;
   border-radius: 0px;
   width: 20rem;
   /* min-width: 18.2rem; */
   /* right: 0px; */

         .header-dropdown-list{
    // height: 150px;
    .list-item-border-bottom{
      border-bottom: 1px solid #e5e6e6;
    }
    p-tabview.tab-panel-underline {
        .ui-tabview{
          padding: 20px !important;
          .ui-tabview-nav li{
            width: 50% !important;
            padding: 0px !important;
          }
        }
      }
   }
 }

但我的样式不适用于primeng tabview。我在我的主列表项(即li)中有这个tabview,并应用了li 的一些填充和宽度primengtabview,但它没有应用我的自定义样式。

【问题讨论】:

  • 在 stackblitz 上创建示例

标签: css angular sass primeng


【解决方案1】:

我已经解决了这个问题。问题是由ViewEncapsulation 引起的。当我将ViewEncapsulation.None 放入我的组件时,我的问题就解决了。

【讨论】:

    【解决方案2】:

    您可以在引用父类的 scss 中使用 ng-deep 和 & 运算符。

    ::ng-deep .notifications-dropdown{
      .dropdown-menu {
       left: 843px !important;
       margin: -0.875rem 0 0;
       font-size: 0.875rem;
       color: #7A8281;
       text-align: left;
       list-style: none;
       border: 0 solid #c8ced3;
       box-shadow: 0px 3px 6px #00000029;
       z-index: 99999;
       top: 74px;
       border-radius: 0px;
       width: 20rem;
       /* min-width: 18.2rem; */
       /* right: 0px; */
    
             .header-dropdown-list{
        // height: 150px;
       & .list-item-border-bottom{
          border-bottom: 1px solid #e5e6e6;
        }
       & p-tabview.tab-panel-underline {
           & .ui-tabview{
              padding: 20px !important;
             & .ui-tabview-nav li{
                width: 50% !important;
                padding: 0px !important;
              }
            }
          }
       }
     }
    

    【讨论】:

    • 能否请您在 stackblitz 上生成演示。我不明白为什么它不起作用。
    • 我无法创建 stackblitz,因为为此我必须将整个 primeng 库集成到 stackblitz 中,并在其中编写我所有必要的 css 样式。你能在屏幕共享上看到问题吗?
    • 我们可以在聊天室里聊天吗?
    猜你喜欢
    • 1970-01-01
    • 2018-06-30
    • 2021-12-01
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    相关资源
    最近更新 更多