简体   繁体   English

html中不同类型的class名字

[英]Different types of class names in html

What is the diff bw什么是差异bw

  • class="name"类=“名称”
  • class="name-new"类=“名字-新”
  • class="name new" What is the difference bw the three and is there any other naming convention too? class="name new" 这三个有什么区别,还有其他命名约定吗?

The difference is that in case:不同之处在于:

  1. class="name" : to the element will be applied only the properties of class "name" class="name" :元素将仅应用 class "name" 的属性
  2. class="name-new" : like point one, but in this case the class is "name-new" class="name-new" :与第一点类似,但在这种情况下,class 是“name-new”
  3. class="name new" : in this case, to element will be applied two different classe: "name" and "new" class="name new" :在这种情况下,将应用两个不同的类:“name”和“new”

The "space" is used to separete multiple classes, same principle is used for the "id". “空格”用于分隔多个类,“id”使用相同的原则。

Also.. the syntax class="name-new" is not equal to use class="name_new" .另外.. 语法class="name-new"不等于使用class="name_new"

  1. class="name"类=“名称”
  2. class="name-new"类=“名称-新”
  3. class="name new"类="新名称"

1 and 2 - works in the same way. 1 和 2 - 以相同的方式工作。 They are just two different classes.它们只是两个不同的类别。 The corresponding style will be applied in the HTML element where they are added.相应的样式将应用于添加它们的 HTML 元素中。

3 - The class 'name' will be applied first, then the class 'new'. 3 - 将首先应用 class 'name',然后应用 class 'new'。 The same/common style properties will be overridden by right side classes.右侧类将覆盖相同/通用样式属性。

.name {
 color:red;
}

.name-new {
 color:blue;
}

.new {
 font-weight: bold;
 color: green;
}

<div class="name"> Name </div> //  will appear in red
<div class="name-new"> New-Name </div> // will appear in blue
<div class="name new"> New Name </div> // will appear in bold-green 

BEM naming convention is explained here BEM 命名约定在这里解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM