<p id = "formatOne">My text here</p>
<!--insert bunch of other stuff in between-->
<!--Reuse formatOne so I don't have to copy-paste the entire CSS formatting again for each use
(similar to functions in most programming languages, write once, call whenever-->
<p id = "formatOne">Different text here</p> <!--like this, but this is obviously wrong since ID must be unique-->有没有一种方法可以使CSS ID像函数一样被调用?
发布于 2022-03-05 18:07:36
每个id元素都应该是唯一的。如果要对不同的HTML元素应用相同的样式,则可以创建class并将相同的类应用于多个HTML元素。
.formatOne {
color:blue;
}<p class="formatOne">My text here</p>
<p class="formatOne">Different text here</p>
发布于 2022-03-05 18:23:25
这在ids中是不可能的。如果您想在css中使用相同的多个用途,那么只有类允许您这样做。
<body>
<div class="asd">
<h1> First </h1>
<p> First line Statement </p>
</div>
<div class="asd">
<h1> Second </h1>
<p> Second line Statement </p>
</div>
<style>
.asd {color : red;
font-size: 20px}
</style>
</body> https://stackoverflow.com/questions/71364609
复制相似问题