我正在尝试选择具有特定data-属性的元素的第一个和最后一个子元素.
该:first-child选择器工作正常,但:last-child不能正常工作.我真的不知道是什么原因引起的.我检查过拼写错误.
CSS
.element[data-type='element']:first-child {
padding-left: 0;
background-color:red !important
}
.element[data-type='element']:last-child {
padding-right: 0;
border-right:0;
background-color:red !important;
}
Run Code Online (Sandbox Code Playgroud)