twitter-bootstrap 从引导程序应用 css 类时的 PrimeNG 日历错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38265324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 00:06:48  来源:igfitidea点击:

PrimeNG calendar bug when applying css class from bootstrap

cssangulartwitter-bootstrapprimengprimeng-calendar

提问by Shimrod

I have this strange bug where I use PrimeNG to display a DatePicker in my application. When I try to use bootstrap's form-control, I get a visual bug.

我有一个奇怪的错误,我使用 PrimeNG 在我的应用程序中显示一个 DatePicker。当我尝试使用 bootstrap 时form-control,出现视觉错误。

Here is my template:

这是我的模板:

<div class="form-group row">
    <div class="form-group col-md-2">
        <label for="valeur">Valeur</label>
        <input type="number" id="valeur" class="form-control" />
    </div>

    <div class="form-group col-md-5">
        <label for="dateDebut">Date de début</label>
        <p-calendar id="dateDebut" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>

    <div class="form-group col-md-5">
        <label for="dateFin">Date de fin</label>
        <p-calendar id="dateFin" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>
</div>

This is the result:

这是结果:

enter image description here

在此处输入图片说明

EDIT

编辑

If it's of any help, here is the generated HTML:

如果有帮助,这里是生成的 HTML:

<div class="form-group col-md-5" _ngcontent-scp-1="">
   <label for="dateDebut" _ngcontent-scp-1="">Date de début</label>
   <p-calendar ng-reflect-show-icon="true" ng-reflect-date-format="dd/mm/yy" ng-reflect-style-class="form-control" styleclass="form-control" id="dateDebut" dateformat="dd/mm/yy" _ngcontent-scp-1="">
      <!--template bindings={
         "ng-reflect-ng-if": "true"
         }-->
      <span ng-reflect-initial-classes="form-control" class="form-control ui-calendar" ng-reflect-raw-class="ui-calendar">
         <input id="dp1467976345328" ng-reflect-value="" class="hasDatepicker ui-inputtext ui-widget ui-state-default ui-corner-left" ng-reflect-raw-class="[object Object]" type="text"><!--template bindings={
            "ng-reflect-ng-if": "true"
            }--><button ng-reflect-icon="fa-calendar" type="button" pbutton="" class="ui-datepicker-trigger ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"><span class="ui-button-icon-left ui-c fa fa-fw fa-calendar"></span><span class="ui-button-text ui-c">ui-button</span></button>
      </span>
      <!--template bindings={
         "ng-reflect-ng-if": "false"
         }-->
   </p-calendar>
</div>

回答by iPaul

I have used the below workaround, and this is working fine in both IE & Chrome:

我使用了以下解决方法,这在 IE 和 Chrome 中都可以正常工作:

<p-calendar [inputStyle]="{'width':'55%'}" ...

Try it

试试看

回答by Stefan Svrkota

PrimeNG's calendar component has four styling attributes, two for adding inline styles and two for adding style (css) classes - style, styleClass, inputStyleand inputStyleClass.

PrimeNG的日历组件有四个造型属性,二为增加内联样式和两个用于添加样式(css)班- ,,和。stylestyleClassinputStyleinputStyleClass

  • styleand styleClassare used to style the component itself (calendar)
  • inputStyleand inputStyleClassare used to style input field
  • stylestyleClass用于设置组件本身的样式(日历)
  • inputStyleinputStyleClass用于样式输入字段

So, this behaviour is not a bug, it's expected behaviour because you are using wrong attribute. If you want to add form-controlclass to PrimeNG's calendar input field, you should use inputStyleClassinstead of styleClassattribute:

因此,此行为不是错误,而是预期行为,因为您使用了错误的属性。如果要将form-control类添加到PrimeNG的日历输入字段,则应使用inputStyleClass代替styleClass属性:

 <div class="form-group col-md-5">
    <label for="dateFin">Date de fin</label>
    <p-calendar id="dateFin" dateFormat="dd/mm/yy" inputStyleClass="form-control" [showIcon]="true"></p-calendar>
</div>

Check entire list of attributes for PrimeNG's calendar component here.

在此处检查PrimeNG日历组件的整个属性列表。

回答by louisl

Adding this css worked for me to get the icon in place as well as adding form-control to the inputStyleClass attribute.

添加此 css 对我有用,可以将图标放置到位,并将表单控件添加到 inputStyleClass 属性中。

.ui-calendar button {
    right: 0;
    top: 0;
}
.ui-calendar {
    width: 100%;
}

<p-calendar dateFormat="dd/mm/yy" showTime="showTime" hourFormat="24" formControlName="start" [showIcon]="true" inputStyleClass="form-control"></p-calendar>

回答by Mina Matta

  1. use "inputStyleClass" property to set the css class
  1. 使用“ inputStyleClass”属性设置css类

<p-calendar inputStyleClass="form-control"></p-calendar>

<p-calendar inputStyleClass="form-control"></p-calendar>

  1. If you are not using Inline form, then override the "ui-calendar" css class
  1. 如果您不使用内联表单,则覆盖“ ui-calendar” css 类
.ui-calendar {
    display: block;
}
.ui-calendar {
    display: block;
}

回答by ravi gupta

Addition to @Srefan Svrkota's answer. You can make another css class that overwrites the form-control class's inline style.

除了@Srefan Svrkota 的回答。您可以创建另一个 css 类来覆盖表单控件类的内联样式。

    .showCalenderInline
    {
    display: inline !important;
    }

and apply to calendar : inputStyleClass="form-control showCalenderInline"

回答by Agitahaja Tanjaya

Hi guys maybe you can try this. im using this for my code

大家好,也许你可以试试这个。我在我的代码中使用这个

add styleClassand inputStyleClasslike this:

添加styleClassinputStyleClass像这样:

<p-calendar styleClass="form-control" inputStyleClass="form-control" ></p-calendar>

<p-calendar styleClass="form-control" inputStyleClass="form-control" ></p-calendar>

and try to change some css, for me like this :

并尝试更改一些 css,对我来说是这样的:

.ui-inputtext{ margin:-7px -12px; }

.ui-button, button.ui-button.ui-state-default, .ui-button.ui-state-default{ top:0px; right: -1px; }

.ui-calendar button{ width: 2.5em; }

.ui-inputtext{ margin:-7px -12px; }

.ui-button, button.ui-button.ui-state-default, .ui-button.ui-state-default{ top:0px; right: -1px; }

.ui-calendar button{ width: 2.5em; }

and the result is enter image description here

结果是 在此处输入图片说明