primeNG p-dropdown stretch 100%

亡梦爱人 提交于 2020-03-17 09:58:32

问题


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.


回答1:


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>



回答2:


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>



回答3:


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




回答4:


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.




回答5:


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

p-dropdown {
    min-width: 80%;
}
.ui-dropdown{
    width: 100%;
}


来源:https://stackoverflow.com/questions/41354416/primeng-p-dropdown-stretch-100

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!