【问题标题】:Which is the correct method of declaration CSS class? and what is different from following methods?声明 CSS 类的正确方法是什么?与以下方法有什么不同?
【发布时间】:2018-12-07 11:49:48
【问题描述】:

声明CSS类的正确方法是什么?和下面的方法有什么不同?

1) div.classname { }
2) .classname { }

【问题讨论】:

标签: html css


【解决方案1】:

两者都有效,但使用方式不同:

  • .classname:样式将应用于每个类classname的元素
  • element.classname:样式将应用于每个此元素的类型元素带有classname

例子:

.class {
  width: 100px;
  height: 100px;
  background-color: blue;
}

div.class {
  background-color: yellow;
}
<div class="class"></div>
<section class="class"></section>
<p class="class"></p>

【讨论】:

  • 通过创建这个 sn-p,您引入了另一个重要因素,即特异性。第二个覆盖第一个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-09
  • 2016-03-31
  • 1970-01-01
相关资源
最近更新 更多