设置 igx-select 的宽度

发布于 2025-01-11 07:11:17 字数 523 浏览 4 评论 0原文

我有多个用于显示下拉列表的 igx-selects。

我想更改此特定 igx-select 的宽度(不适用于我拥有的所有 igx-selects)以及列表的字体大小。当我尝试时,没有任何效果。这在SCSS中可能吗?

这是我的 igx-select 块。

  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item style="width: 430px" *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

非常感谢!

I have multiple igx-selects that are used to display a drop-down list.

I want to change the width of this particular igx-select (not for all igx-selects that I have) as well as the font-size of the list. As I tried nothing worked. Is this possible in SCSS?

Here is my igx-select block.

  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item style="width: 430px" *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

Thank you very much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在你怀里撒娇 2025-01-18 07:11:17

IgxSelect 的宽度取决于其父容器的宽度。如果你想改变 igxSelect 的宽度,你应该像这样设置它的父级的宽度:

<div style="width: 430px">
  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

如果你需要设置选择下拉列表的宽度,这有点棘手。实现此目的的一种方法是处理选择的 opening 事件。在处理程序中,您可以设置选择切换元素的宽度,这是下拉列表,如下所示:

public selectOpening(evt: IBaseCancelableBrowserEventArgs) {
   evt.owner.toggleDirective.element.style.width = "430px";
}

请记住,这可能会破坏选择下拉列表的定位。可以通过应用于项目本身的 CSS 来设置所选项目的字体,如下所示:

  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item style="font-size: 15px;" *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

同样,这可能会破坏所选项目的定位。设置项目大小的一种方法是通过 DisplsyDensity。

IgxSelect's width depends on the width of its parent container. If you want to change the width of igxSelect you should set the width of its parent like this:

<div style="width: 430px">
  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

If you need to set the width of the select's dropdown this is a little more tricky. One way to achieve this is to handle opening event of the select. In the handler you can set the width of the select toggle element, this is the dropdown, like this:

public selectOpening(evt: IBaseCancelableBrowserEventArgs) {
   evt.owner.toggleDirective.element.style.width = "430px";
}

Keep in mind this may brake the positioning of the select dropdown. Setting of the font of the select items could be done via CSS applied to the item itself like this:

  <igx-select #selectCity
              placeholder="Select city"
              [overlaySettings]="overlaySettings"
              [(ngModel)]="city" name="cities">
      <igx-select-item style="font-size: 15px;" *ngFor="let item of cities" [value]="item">
          {{ item }}
      </igx-select-item>
  </igx-select>

Again this may break the positioning of the select items. One way to set the size of the items is via DisplsyDensity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文