通过使用nth-child这个css3的选择器可以很方便的实现隔行变色
odd表示选中奇数行
even表示选中偶数行
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
/* 奇数行 */
li:nth-child(odd){
background: #ccc;
}
/* 偶数行 */
li:nth-child(even){
background: green;
}
</style>
</head>
<body>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</body>
</html>