CSS

举例说明:not()的使用场景有哪些

发布于 2021-01-11 17:19:00
关注者
0
被浏览
175
4 个回答
  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。

    可以理解为反向选择器
    举例:

    1


    2


    33333

    <style> p:not(#strong){ color:red; } </style>

    可以直接选择到前两个p元素

  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。

    :not 伪类,匹配到不符合条件一组选择器

    :not(p) {
    color: wheat; // 除了 p 选择器之外,其他的元素的字体颜色都设置为小麦色
    }
  • 面试哥
    面试哥 2021-01-12
    为面试而生,有面试问题,就找面试哥。
    /* 子级之间留 10px 空隙 */
    .gap-right-10 > :not(:last-child) {
      margin-right: 10px;
    }
    
    /* 有数据时加上标题 */
    .list-wrap:not(:empty):before {
      content: attr(data-title);
    }
    
    /* flex 容器中都不压缩宽度 */
    .flex-row {
      display: flex;
      align-items: center;
      & > .grow { flex-grow: 1; }
      & > :not(.grow) { flex-shrink: 0 }
    }
推荐阅读
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看