html - :first-child selecting all elements

标签 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/

上一篇:php - 如何将结帐页面中的文本 "place your order"更改为 "Book"?

下一篇:html - Bootstrap 将表单固定到页面底部

相关文章:

html - 使元素溢出到父元素之外

css - 为 CSS 作用域生成的 Angular 属性未应用于组件的内部元素

css - Bootstrap4 问题 : proper column structure inside and outside a container

php - 如何为表格的每一行放置一个表格

javascript - 随着浏览器调整大小更改文本

jquery - 选框跨度/跨度内容

css - 如何为此翻转添加过渡?

html - 无法将图像与内部 CSS 正确对齐

css - Bootstrap 4 和 SCSS - 基于基类覆盖主类

css - 移动友好的 Bootstrap 面包屑标签