html - 指定为不同类设置样式的类

标签 html css

我如何定义一个类来为其中的某些元素设置样式?

我已经试过了,但是元素没有样式:

<div id="test">
<p>hello</p>
<h3>how are you</h3>
</div>

#test {
  p {
    color: red;
  }
  h3{
    color: blue;
  }
}

#test p { } 不是我要找的....我确定我已经在示例中看到上面的代码有效。

最佳答案

重新阅读代码,我有理由确定您看到的有效代码是 LESS 或 Sass,它们被编译成 CSS。

例如,在 this codepen 上你会注意到我在 Sass 的侧面设置了一些元素。此代码被编译为 CSS,它不具备选择器的灵 active 。

SCSS:

#test{
  h1{
    color:blue;
  }
  p{
    color:red;
  }
}

编译后的 CSS:

#test h1 {
  color: blue;
}
#test p {
  color: red;
}

关于html - 指定为不同类设置样式的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41316797/

相关文章:

jquery - BootStrap 多个事件导航选项卡问题

html - Twitter Bootstrap 网格在页面右侧显示白色边距

html - 动画完成后如何阻止文本移动?

javascript - 如何在jquery中相应地用新值替换输入值

html - 奇怪的 css 行为 - 图像内联不在下方

javascript - 如何在 Internet Explorer 中开始自动下载文件?

css - 绝对定位的 child 与边界

html - 级联 CSS :not pseudo-class

jQuery 插件创建

html - 单选按钮位置 HTML/CSS