1.无序列表(ul)

各个列表项之间没有顺序之分,通常是并列的


  1. 语法:
  2. <ul>
  3. <li></li>
  4. </ul>
  5. 功能:
  6. <ul> 标签定义无序列表。
  7. <ul> 标签与<li>标签一起使用,创建无序列表。

2.案例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <style type="text/css">
  6. ul{
  7. list-style-type:none;
  8. margin:0px auto;
  9. padding:0px;
  10. background-color:#000000;
  11. color:#ffffff;
  12. display:flex;
  13. justify-content:center;
  14. }
  15. li{
  16. width:200px;
  17. line-height:50px;
  18. text-align:center;
  19. background-size:100% 100%;
  20. }
  21. ul li:nth-of-type(6){
  22. background-image:url("http://www.yyfun001.com/res/htmlclassics/full/images/136.jpg");
  23. }
  24. ul li:not(#first){
  25. background-color:green;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <ul>
  31. <li id="first">首页</li>
  32. <li>国内新闻</li>
  33. <li>国际新闻</li>
  34. <li>体育新闻</li>
  35. <li>财经新闻</li>
  36. <li>娱乐新闻</li>
  37. </ul>
  38. </body>
  39. </html>1 ·

image.png

  1. 代码讲解:
  2. ul{
  3. list-style-type:none;
  4. margin:0px auto;
  5. padding:0px;
  6. background-color:#000000;
  7. color:#ffffff;
  8. display:flex;
  9. justify-content:center;
  10. }
  11. list-style-type:none; 设置列表样式类型无
  12. margin:0px auto; 设置上下外延边距为0,左右外延边距距中
  13. padding:0px; 设置内部边距为0
  14. background-color:#000000; 设置背景色为黑色
  15. color:#ffffff; 设置文字颜色为白色
  16. display:flex; 设置ul标签为弹性容器
  17. justify-content:center; 设置容器内容距中
  18. 2li标签样式
  19. li{
  20. width:200px;
  21. line-height:50px;
  22. text-align:center;
  23. background-size:100% 100%;
  24. }
  25. width:200px; 设置宽度为200像素
  26. line-height:50px; 设置行高为50像素
  27. text-align:center; 设置文本距中
  28. background-size:100% 100%; 设置背景图大小长100%、高100%显示
  29. 3、:nth-of-type()
  30. ul li:nth-of-type(6){
  31. background-image:url("http://www.yyfun001.com/res/htmlclassics/full/images/136.jpg");
  32. }
  33. ul li:nth-of-type(6) 选择ul下第6li元素
  34. background-image:url("http://www.yyfun001.com/res/htmlclassics/full/images/136.jpg"); 设置背景图
  35. 4、:not(id)
  36. ul li:not(#first){
  37. background-color:green;
  38. }
  39. ul li:not(#first) 选择ul下除idfirstli标签以外的元素
  40. background-color:green; 设置背景颜色为绿色