首页 > 其他分享 >nz-select下拉框自适应宽度

nz-select下拉框自适应宽度

时间:2024-10-20 20:22:58浏览次数:1  
标签:name id nz 宽度 设置 下拉框 select

原文链接:nz-select下拉框自适应宽度 – 每天进步一点点

数据如下:

listOfData=[ { "name":"标题1", "id":"1" }, { "name":"标题12", "id":"2" }, { "name":"标题123", "id":"3" }, { "name":"标题1234", "id":"4" }, { "name":"标题12345", "id":"5" }, ] <nz-select   > <nz-option *ngFor="let item of listOfData" [nzLabel]="item.name" [nzValue]="item.id" > </nz-option> </nz-select>

使用nz-select时,如果没有指定宽度就会是下面的样子:

如果设置宽度是80px,那么就会变成这样:

<nz-select style="width: 80px;" > <nz-option *ngFor="let item of listOfData" [nzLabel]="item.name" [nzValue]="item.id" > </nz-option> </nz-select>

如果宽度设置成300px,就会变成下面这样:

可以看出,如果宽度设置过长就浪费了很多空间,如果设置了过短就无法显示部分数据。所以我们需要设置自适应宽度。

代码如下:

<nz-select [nzDropdownStyle]="{ width: 'fit-content', 'min-width': '80px' }" style="min-width: 80px;" > <nz-option *ngFor="let item of listOfData" [nzLabel]="item.name" [nzValue]="item.id" > </nz-option> </nz-select>

通过设置最小宽度80px, 然后设置宽度自适应即可。

 

标签:name,id,nz,宽度,设置,下拉框,select
From: https://www.cnblogs.com/longkui-site/p/18487808

相关文章

  • vue3 深度响应式是否正常测试,以select options作为例子测试,select options后赋值是否
    <template><divclass='box'><templatev-for="(ditem,dindex)indata1":key="dindex"><el-selectv-model="ditem.value"clearablefilterable><el-optionv-for="ite......
  • 第九届中国大学生程序设计竞赛 深圳站(CCPC 2023 Shenzhen Site)
    Preface由于这周末大家都要补课,因此只能把训练挪到周五晚上了然后祁神打了2h就跑路去上课了,前期我和徐神也因为成都站相关的一些准备工作被迫脱离了比赛因此最后发现机时不够会写的D赛后30min过了,感觉正常打的话应该能出9题A.AGoodProblem考虑按值域分治,从二进制位......
  • select、poll和epoll区别
    函数原型intselect(intnfds,structfd_set*readfds,structfd_set*writefds,structfd_set*execptfds,structtimeval*timeout);intpoll(structpollfd*fds,nfds_tfds,inttimeout);epoll:intepoll_create(intsize);intepoll_ctl(intepollfd,intop,intfd,st......
  • jsp二手车市场商户管理系492nz--程序+源码+数据库+调试部署+开发环境
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表商家,店铺信息,二手车辆,租赁申请,退租申请,续租申请,提醒信息开题报告内容一、研究背景随着二手车市场的快速发展,商户管理问题日益凸显。商户信息散乱、管理......
  • el-select 下拉搜索框
    //搜索框下拉:deep(.el-select__placeholder.is-transparent){color:#fff!important;font-size:1rem!important;}:deep(.el-select__placeholder){color:#fff!important;font-size:1rem!important;}:deep(el-select__caret){color:#fff!imp......
  • wpf combobox 去除下拉框展开时自动选择文本
    新增一个自定义控件继承ComboBox,同事在输入事件之前打开下拉框publicpartialclassComboBoxEx:ComboBox{publicComboBoxEx(){}privateintcaretPosition;publicoverridevoidOnApplyTemplate(){base.OnApplyTemplate(......
  • 【未公开0day】9.9付费进群系统 wxselect SQL注入漏洞【附poc下载】
    免责声明:本文仅用于技术学习和讨论。请勿使用本文所提供的内容及相关技术从事非法活动,若利用本文提供的内容或工具造成任何直接或间接的后果及损失,均由使用者本人负责,所产生的一切不良后果均与文章作者及本账号无关。fofa语法body="template/layuiadmin/xinadmin"一、漏洞......
  • NZOJ 模拟赛7
    T1字符串小X十分热爱学习。有一天,他刚学完“漂亮的k字符串”的概念:给定长度为n的字符串和整数k,k能整除n,如果该字符串满足以下两个条件:s是一个回文串,即对于任意1≤i≤n,Si=Sn+1-i(其中Si表示字符串中第i个字母)s以k为周期,即对于任意1≤i≤n-k,Si=Sk+i(其中Si表示字符串中......
  • wpf 下拉框添加选项中删除数据
    需要根据实际需求在按钮的对应事件或者Command中添加逻辑<StyleTargetType="ComboBox"x:Key="DeleteComboBoxStyle"><SetterProperty="ItemContainerStyle"><Setter.Value><!--ComBoxItem--><......
  • 在 .NET 中的 ConvertAll 和 Select 方法哪个性能好
    .NET的List中提供了ConvertAll和Select两个方法,在开发中实际上应该使用哪一个?接下来通过基准测试脚本来对比性能。先编写基准测试脚本:[MemoryDiagnoser]publicclassBenchmarksTerrible{privatereadonlyList<Order>_orders;publicBenchmark......