gpt4 book ai didi

css - PrimeNG 日历 - 覆盖默认样式

转载 作者:行者123 更新时间:2023-12-04 15:53:51 25 4
gpt4 key购买 nike

使用 angular,我在一个组件中使用 p-calendar 并创建了一个从我的组件调用的 CSS 类。无论我做什么,我都无法覆盖样式。

CSS

.ui-calendar .ui-calendar-button {
height: 34px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 900em;
border-left: 0 none;
}

HTML

<div class="form-group col-xs-3 col-md-3"
[ngClass]="{
'has-error':(ersaForm.get('effectiveDt').touched || ersaForm.get('effectiveDt').dirty ) &&
!ersaForm.get('effectiveDt').valid
}">
<label for="effectiveDtId" class="control-label">Effective Date</label><br />

<p-calendar formControlName="effectiveDt" id="effectiveDtId" [showIcon]="true"
inputStyleClass="form-control "
class="ui-calendar ui-calendar-button"
[style]="{'width': '100%','display': 'inline-flex','height':'34px'}" ></p-calendar>

</div>

*************************************************** *****更新*********************************************

我将我的 SCSS 文件更改为

::ng-deep .only-style-this .ui-calendar .ui-calendar-button { 
height: 34px !important;
border-top-left-radius: 0 !important;
}

HTML

  <div class="form-group col-xs-3 col-md-3 only-style-this"
[ngClass]="{
'has-error':(ersaForm.get('effectiveDt').touched || ersaForm.get('effectiveDt').dirty ) &&
!ersaForm.get('effectiveDt').valid
}">
<label for="effectiveDtId" class="control-label">Effective Date</label><br />

<p-calendar formControlName="effectiveDt" id="effectiveDtId" [showIcon]="true"
inputStyleClass="form-control"

styleCalss=".ui-calendar .ui-calendar-button"
[style]="{'width': '100%','display': 'inline-flex','height':'34px'}" ></p-calendar>

</div>

警告

验证 (CSS 3.0):“::ng-deep”不是有效的伪元素。

最佳答案

您不能调整子组件的 css,它会破坏封装。这会起作用但是是 deprecated :

::ng-deep .ui-calendar .ui-calendar-button {
height: 34px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 900em;
border-left: 0 none;
}

这基本上与将其添加到全局样式表中相同。然而,全局样式只会在组件第一次加载时应用,这使得它非常糟糕。为了安全起见,您可以将组件包装在“only-style-this”类中并执行:

::ng-deep .only-style-this .ui-calendar .ui-calendar-button {
...
}

或者,prime-ng 通常允许您将样式传递给它的大部分组件。

如果您查看 docs你会发现有一个样式属性你可以使用。您可能还想使用其他属性,例如 inputStyle。

关于css - PrimeNG 日历 - 覆盖默认样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52723585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com