问题
I'm trying following CSS, it works in Firefox and Chrome but does not work in the Safari (5.1). I have checked Safari supports nth-child. What I'm doing wrong?
CSS:
option:nth-child(2){
display: none;
}
HTML:
<select>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
Demo: http://jsfiddle.net/Kv9tj/
回答1:
You can always use: nth-of-type(2) .
Browser support for :nth-of-type is fairly decent... Firefox 3.5+, Opera 9.5+, Chrome 2+, Safari 3.1+, IE 9+.
I hope this will help you!!!
回答2:
I think your problem is not nth-child
, but display: none
on option
.
For example, see this answer: https://stackoverflow.com/a/15025961/39068 (to a similar question).
It says that you can not set display: none
on option
in Safari or IE.
来源:https://stackoverflow.com/questions/17312140/nth-child-does-not-work-in-safari