【问题标题】:Nested classes and tags [duplicate]嵌套类和标签[重复]
【发布时间】:2019-05-26 06:12:29
【问题描述】:

我知道它的基本知识,我知道有人问它,我只是不知道它的正确术语,并且无法在 Google 上查找它。

我想将 tag 嵌套在 CSS class 中:

.fullPageGallery
{
  width: 100%;
  height: 100%;

    >h1
    // some properties of h1 here (h1 is a tag inside this class)

    .AnotherClass
    //some properties of another class here (a div inside this class)
}

【问题讨论】:

  • 这里绝对是骗子

标签: css


【解决方案1】:

你不能在纯 CSS 中做到这一点 - 使用 SCSS/SASSLess

(以下内容应适用于上述两种语言):

.fullPageGallery {
    width: 100%;
    height: 100%;
    h1 { /* Properties */ }
    .AnotherClass { /* Properties */ }
}

【讨论】:

  • 我需要包含一些文件/框架才能使用它吗?还是就这样写?
  • 您需要包含来自网站的脚本 - 这是一个外部插件。
  • 请不要在问题中添加less/sass标签。这没有意义,它完全改变了问题的含义。 OP 正在询问 CSS 方式,但他不知道 SASS/LESS
【解决方案2】:

你不能使用普通的 CSS 来做到这一点。但是,您可以使用作为 CSS 预处理器的 Less 或 Sass (SCSS),并根据需要支持选择器嵌套。

它们通过构建过程被编译为标准 CSS。

阅读更多关于 Sass here 和关于 Less here 的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2021-12-14
    • 2011-06-13
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 2013-08-01
    相关资源
    最近更新 更多