css选择器
css 选择第一个标签,倒数第二个标签,最后一个标签
选择第一个标签
span:nth-child(1)
选择倒数第二个标签
p:nth-last-child(2)
选择最后一个标签:
p:last-child
找到只有一个子节点的元素
ul > li:first-child:last-child
ul > li:only-child
将 n 个元素, 按数量 m 进行分组,每组元素循环显示两种不同的样式
vue
<script setup lang="ts"></script>
<template>
<ul>
<template v-for="index of 20" :key="index">
<li>{{ index }}</li>
</template>
</ul>
</template>
<style scoped>
ul li:nth-of-type(6n + 1),
ul li:nth-of-type(6n + 2),
ul li:nth-of-type(6n + 3) {
color: red;
}
</style>