我试图通过搜索来找到答案,但结果是空的。基本上我不确定如何正确处理一些 CSS 设计。我有一个用于许多页面的模板。我需要设计几个容器。例如,我有一个名为“box 1”的 div,我在许多不同的页面上使用它。我已经用 css 在外部设置了文本框的长度。我现在如何使用“box 1”div 在不同页面中设置文本框的样式,而不会覆盖我的原始样式。有没有办法给这些贴上标签。这可能吗?
提前致谢
您可以应用多个类:
.box {
background-color: red;
}
.box.new_style {
font-weight: bold;
}
如果你创建一个 div:
<div class="box">This is a box</div>
它将有一个红色背景,然后是另一个 div:
<div class="box new_style">This is a box</div>
它将具有红色背景和粗体文本。
由于您提到了多个页面,您可以将一个类附加到容器或body
,然后使用:
<body class="some_page">
<div class="box">
....
然后:
.some_page .box { font-weight: bold; }