Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML:为什么有这么多的类名_Html_Css - Fatal编程技术网

HTML:为什么有这么多的类名

HTML:为什么有这么多的类名,html,css,Html,Css,为什么有这么多类名,比如home,page template default,page,page-id-12。我什么时候应该用这么多?一个类名还不够吗 从技术上讲,如果您愿意,您可以只使用一个样式,但问题是您将无法重用某些样式,并且如果您决定将其复制粘贴到一组类名中,则很难进行更新 比如说 .card { padding: 10px; background-color: white; border: black; border-radius: 5px; } .card-blue { backg

为什么有这么多类名,比如home,page template default,page,page-id-12。我什么时候应该用这么多?一个类名还不够吗


从技术上讲,如果您愿意,您可以只使用一个样式,但问题是您将无法重用某些样式,并且如果您决定将其复制粘贴到一组类名中,则很难进行更新

比如说

.card {
padding: 10px;
background-color: white;
border: black;
border-radius: 5px;
}

.card-blue {
background-color: blue;
}
.card-red {
background-color: red;
}
使用.card类,您可以将其添加到多个元素中,并添加更多类以进行自定义,而无需重复多行css

<div class="card card-red">Red Card</div>
<div class="card card-blue">Blue Card</div>

因为这些都是从CMS添加的默认类

如果要为所有页面添加css,可以将页面用作css中的类

正文.第{}页