元素的 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
CSS for element SELECT multiple=yes
提问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 select
element to notbe in multi-selection mode, the multiple
attribute must be entirely omitted. Even if you set multiple="no"
or multiple="false"
, the standard behavior is the same as HTML multiple
or 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 select
with that attribute:
考虑到这一点,使用 CSS3:not()
选择器排除select
具有该属性的任何内容:
select:not([multiple]) {
height: 30px;
}
Or if you need IE7+ support, apply the height to all select
elements 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.
我不知道这是否回答了问题。这是一种贡献。