ul { list-style: none; /*去掉ul前面的默认符号*/ margin: 0; padding: 0; } ul li { padding: 10px; /*设置每个li的内边距*/ border-bottom: 1px solid #ccc; /*设置每个li的下边框*/ } ul li:last-child { border-bottom: none; /*去掉最后一个li的下边框*/ } ul li a { text-decoration: none; /*去掉a标签的下划线*/ color: #333; /*设置字体颜色*/ display: block; /*将a标签转换为块级元素,使它充满整个li的区域*/ } ul li a:hover { background-color: #f4f4f4; /*鼠标悬停时改变背景颜色*/ }
解释:
大家首先设置ul的样式,去掉ul前面的默认符号,并且把ul的外边距和内边距都设为0。接着,大家为ul中的每个li元素设定样式,给它们添加内边距和下边框,并且去掉最后一个li的下边框。大家让li内的a标签转换为块级元素,使它充满整个li的区域。然后大家为a标签添加样式,去掉下划线并且设置字体颜色。最后,大家在鼠标悬停时改变li的背景颜色。