当前位置:Gxlcms > css > not()选择器的使用

not()选择器的使用

时间:2021-07-01 10:21:17 帮助过:283人阅读

这次给大家带来not()选择器的使用,使用not()选择器的注意事项有哪些,下面就是实战案例,一起来看一下。

本文中用到的是CSS3新增的:not()伪类选择符,可以匹配不含有选择符的元素。假定有个列表,每个列表项都有一条底边线,但是最后一项不需要底边线

实例代码如下:

  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>使用:not() 最后一行li不添加边框</title>
  6. <style type="text/css"></p>
  7. <p>/*
  8. 使字体在所有设备上都达到最佳的显示
  9. */
  10. html {
  11. -moz-osx-font-smoothing: grayscale;
  12. -webkit-font-smoothing: antialiased;
  13. text-rendering: optimizeLegibility;
  14. }</p>
  15. <p>/*
  16. 给body添加阴影
  17. */
  18. body:before {
  19. content: "";
  20. position
  21. : fixed;
  22. top: -10px;
  23. left: 0;
  24. width: 100%;
  25. height: 10px;
  26. -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
  27. -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
  28. box-shadow: 0px 0px 10px rgba(0,0,0,.8);
  29. z-index: 100;
  30. }</p>
  31. <p>/*
  32. 设置列表
  33. */
  34. .listItem {
  35. border: 1px solid red;
  36. }
  37. .listItem ul {
  38. width: 100%;
  39. overflow
  40. :hidden;
  41. }
  42. .listItem ul,listItem li {
  43. margin:0;
  44. padding
  45. :0;
  46. list-style
  47. :none;
  48. }
  49. .listItem li {
  50. margin-left
  51. :10px;
  52. }
  53. /*
  54. li 最后一个元素不添加边框
  55. */
  56. .listItem li:not(:last-child) {
  57. border-bottom:1px solid green;
  58. }
  59. /*
  60. 与第一个li相连兄弟
  61. */
  62. .listItem li
  63. :first-child
  64. ~ li { border-left: 1px solid #666; }
  65. </style>
  66. </head></p>
  67. <p><body></p>
  68. <p> <p class="listItem">
  69. <ul>
  70. <li>列表1</li>
  71. <li>列表2</li>
  72. <li>列表3</li>
  73. <li>列表4</li>
  74. <li>列表5</li>
  75. </ul>
  76. </p>
  77. </body>
  78. </html>

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

三种绝对定位元素的水平垂直居中的办法

width:100%;与width:auto的使用区别

以上就是not()选择器的使用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行