primeNG p-dropdown stretch 100%

2020-06-07 06:54发布

How to set the primeNG dropdown width to stretch 100% inside its container?

It seems to have fixed element.style and the .ui-dropdown{ width: 100% } override does not work.

标签: css primeNg
5条回答
Juvenile、少年°
2楼-- · 2020-06-07 07:05

"autoWidth" did not work for me, I just did this in my CSS:

p-dropdown {
    min-width: 80%;
}
.ui-dropdown{
    width: 100%;
}
查看更多
Viruses.
3楼-- · 2020-06-07 07:06

You should be editing a class in a primeng.min.css file as below,

.ui-dropdown .ui-dropdown-panel {
  min-width: 100%;
  width: max-content;
}
<p-dropdown id="id" [options]="list"></p-dropdown>

then Dropdownlist should take size of biggest option.

查看更多
别忘想泡老子
4楼-- · 2020-06-07 07:19

You should be writing in a css file using the mentioned class as below,

.ui-dropdown    {
  width:100% !important;
}

Set it to be !important

LIVE DEMO

查看更多
beautiful°
5楼-- · 2020-06-07 07:20

In my case I used autoWidth = false and set style attrribute like below

<p-dropdown [options]="educationLevels" [(ngModel)]="selectedEducationLevel" 
name="educationlevel" autoWidth="false" [style]="{'width':'100%'}"></p-dropdown>
查看更多
Deceive 欺骗
6楼-- · 2020-06-07 07:22

I found to use the Responsive approach and apply .ui-fluid style with Grid CSS at container while p-dropdown should have the [autoWidth]="false" attribute.

Example:

<div class="ui-grid ui-grid-responsive ui-fluid">
    <div class="ui-grid-row">
        <div class="ui-grid-col-12">
            <p-dropdown [autoWidth]="false"></p-dropdown>
        </div>
    </div>
</div>
查看更多
登录 后发表回答