Select2下拉框中内容换行,丑,尝试添加option宽度及水平滚动条解决
问题:页面要求select固定宽度与其他框宽度保持一致,导致下拉框中的文字换行,特丑,修改select2.css样式
1.修改文本框样式
11行左右
.select2-container .select2-selection--single {
box-sizing: border-box;
cursor: pointer;
display: block;
height: 21px;/*设置文本框的高度*/
user-select: none;
-webkit-user-select: none; }
130行左右
.select2-container--default .select2-selection--single {
background-color: #fff;
border: 1px solid #aaa;
/* border-radius: 4px; */ }/*设置文本框的圆角,这里需要和其他框保持一致,故注释掉*/
.select2-container--default .select2-selection--single .select2-selection__rendered {
color: #444;
line-height: 20px; }/*设置文本框中文本显示位置,随文本框高度修改*/
2.修改下拉框样式
7行左右
.select2-results__option[aria-selected] {
cursor: pointer;
width: 300px;/*设置下拉框option的宽度*/
}
260行左右
.select2-container--default .select2-results > .select2-results__options {
max-height: 200px;
overflow-x: auto; /*添加水平滚动条*/
overflow-y: auto; }