元素的 CSS SELECT multiple=yes

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8188557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:11:51  来源:igfitidea点击:

CSS for element SELECT multiple=yes

csscss-selectors

提问by Yannick

I want to be able to define a height for the select element when its multiple to false

我希望能够在 select 元素的倍数为 false 时为其定义高度

select{height: 30px;}

But I don't want it to be applied when the select has the multiple=yes.

但是我不希望在选择具有 multiple=yes 时应用它。

Can it be defined in CSS?

可以在CSS中定义吗?

回答by BoltClock

First things first, in order for a selectelement to notbe in multi-selection mode, the multipleattribute must be entirely omitted. Even if you set multiple="no"or multiple="false", the standard behavior is the same as HTML multipleor XHTML multiple="multiple". For more information, refer to the HTML spec.

首先,为了使select元素处于多选模式,multiple必须完全省略该属性。即使您设置multiple="no"multiple="false",标准行为也与 HTMLmultiple或 XHTML相同multiple="multiple"。有关更多信息,请参阅HTML 规范

With this in mind, use the CSS3 :not()selector to exclude any selectwith that attribute:

考虑到这一点,使用 CSS3:not()选择器排除select具有该属性的任何内容:

select:not([multiple]) {
    height: 30px;
}

Or if you need IE7+ support, apply the height to all selectelements then reset it for those with that attribute:

或者,如果您需要 IE7+ 支持,请将高度应用于所有select元素,然后为具有该属性的元素重置高度:

select {
    height: 30px;
}

select[multiple] {
    height: auto;
}

回答by Rodrigo Carmine

select[multiple]{
height: 30px
}

select[multiple]:focus{
height:auto
}

I don′t know if this answers the question. It′s a contribution.

我不知道这是否回答了问题。这是一种贡献。