【问题标题】:CSS target text input fields by order [duplicate]按顺序排列的CSS目标文本输入字段[重复]
【发布时间】:2020-08-12 22:01:30
【问题描述】:

我有一个带有以下文本输入字段的 html 表单。没有class,没有id,同类型。

我需要以不同的方式设置它们的样式。

是否可以使用纯 CSS 按顺序定位它们?

类似:

CSS(不工作)

input[0] {
  height: 100px;
}

input[1] {
  height: 150px;
}

input[2] {
  height: 200px;
}
<input name="arr[]" type="text">
<input name="arr[]" type="text">
<input name="arr[]" type="text">

我知道我可以使用 :nth-child:nth-of-type,但我想知道是否还有其他方法可以定位这些元素,例如我的CSS 示例。

谢谢。

【问题讨论】:

标签: html css forms


【解决方案1】:

试试 :nth-child,像这样:

input:nth-child(1) {
  height: 100px;
}
input:nth-child(2) {
  height: 150px;
}
input:nth-child(3) {
  height: 200px;
}

【讨论】:

  • 它对我不起作用。它适用于:nth-​​of-type,而不是。无论如何,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 2017-08-20
  • 2015-04-07
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多