问题描述
我有一个带有以下文本输入字段的html表单。没有课程,没有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示例。
谢谢。
解决方法
尝试:nth-child,像这样:
input:nth-child(1) {
height: 100px;
}
input:nth-child(2) {
height: 150px;
}
input:nth-child(3) {
height: 200px;
}