热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Sass&:not(:first-type)使用类隐藏所有内容-Sass&:not(:first-of-type)hideseverythingwiththeclass

Ihaveadivstructurethatlookslikethis:我有一个这样的div结构:<divclassjumbotronjumbotron-fluid

I have a div structure that looks like this:

我有一个这样的div结构:

...
...

And in my Sass file I am trying to hide all but the first of type for .slide:

在我的Sass文件中,我试图隐藏除第一个类型的。slide:

.jumbotron {
  background-color: $white;
  color: $black;
  margin-bottom: 0;
  min-height: 100vh - $navbar-height;
  .slide {
    &:not(:first-of-type) {
      display: none;
    }
  }
}

This seems to be hiding all the .slide divs rather than "all but the first" as intended, doesn't it?

这似乎隐藏了所有的。slide divs,而不是“除了第一个以外的所有”,不是吗?

1 个解决方案

#1


3  

:first-of-type can only be used to select elements not classes within the parent element.

:第一个类型只能用于选择父元素中的元素而不是类。

https://developer.mozilla.org/en-US/docs/Web/CSS/:first-of-type

https://developer.mozilla.org/en-US/docs/Web/CSS/ first-of-type

If you want to hide all but the first .slide you can use the general sibling selector ~

如果要隐藏除第一个.slide之外的所有内容,可以使用通用的同胞选择器~

.jumbotron {
    background-color: $white;
    color: $black;
    margin-bottom: 0;
    min-height: 100vh - $navbar-height;
    .slide {
        ~ .slide {
            display: none;
        }
    }
}

推荐阅读
author-avatar
大布丁
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有