<分区>
标签 html css bootstrap-4
<分区>
只需要选择 select 标签中的第一个选项,并赋予它与其他选项不同的颜色。
:first-child
, :first-of-type
, :nth-of-type
HTML
<div class="input">
<select>
<option value="" selected disabled>Your interests</option>
<option value="" >Test</option>
<option value="" >Test</option>
</select>
CSS
.input select:first-child
{
color: gray;
}
只需要将第一个选项标签的字体颜色设置为灰色。 使用第一个 child 不断选择所有选项标签并为它们提供相同的灰色。 如果有意义,请使用 bootstrap 4。
最佳答案
您需要将 css 应用到 option
而不是 select
.input select option:first-child
{
color: gray;
}
<div class="input">
<select>
<option value="" selected disabled>Your interests</option>
<option value="" >Test</option>
<option value="" >Test</option>
</select>
</div>
关于html - :first-child selecting all elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57555863/