基于 css3 实现隔行换色

385 阅读1分钟

需求

  • 使用 ul 和 li 布局一个列表
  • 实现隔行换色
  • 实现鼠标划过高亮选择

效果

知识点

  • 移除省略...
text-overflow:ellipsis;
white-space:nowrap;
overflow:hidden
  • 奇数行选取
  • 鼠标移动

css3 选择器

  1. nth-child(N): 当前容器的所有子元素中的第一个并且标签名必须是前面的选择器
  2. nth-of-type(N): 先给当前容器按照某个标签名进行分组,获取组中的第 N 个
  3. nth-of-type(even): 偶数行
  4. nth-of-type(3n+1): 隔三行换色,每三行一组;一组中的第一个
  5. nth-of-type(3n+2): 隔三行换色,每三行一组;一组中的第二个
  6. nth-of-type(3n): 隔三行换色,每三行一组;一组中的第三个