【问题标题】:How to select only the first input with my css? [duplicate]如何使用我的 CSS 仅选择第一个输入? [复制]
【发布时间】:2020-12-03 23:01:57
【问题描述】:

您好,请您帮忙处理一些 CSS, 我有这个代码

<div>
  <div>
     <input class="test"/>
  </div>
</div>
<div>
  <div>
     <input class="test"/>
  </div>
</div>
<div>
  <div>
     <input class="test"/>
  </div>
</div>

我只想在第一次输入时更改一些属性,有人可以帮我解决这个问题吗? 谢谢

【问题讨论】:

  • 我给出了答案。你是这个意思吗?
  • 是的,但我不能接受你的回答,因为我没有这样做的声誉,你

标签: css


【解决方案1】:

在您的情况下,您可以使用这些 css 规则:

div:nth-child(1) div input.test {
  color: green;
}

div:first-of-type div input.test {
  color: green;
}

【讨论】:

  • 乐于助人:)
猜你喜欢
  • 1970-01-01
  • 2019-04-29
  • 2015-11-03
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多