有没有办法将 class/id 添加到选择器?
Is there a way to add a class/id to a selector?
假设我有一些 HTML 看起来像这样:
<div id="non-adjustable">
<a id="adjustable-a" href="example.html">
<div id="adjustable-div">Button</div>
</a>
</div>
然后我有一个样式表,其中包含一些我想添加到 #non-adjustable
div 的精彩动画。
Limitations/Requirements:
- 我无法编辑
#non-adjustable
div的HTML,所以我无法向[=]添加class 50=].
- 我可以编辑
#non-adjustable
div下的HTML(#adjustable-a
和#adjustable-div
)。
- 我可以编辑CSS但我不能从动画样式表中获取样式(我只能使用样式表中的classes) .
基本上,如果这是一件事,我希望能够做到这一点:
<style type="text/css">
#non-adjustable(.fantastic-animation) {
/*Other Declarations*/
}
</style>
但这要么不起作用,要么我做错了。还有人有其他想法吗?
您可以使用 :before 和 :after 伪元素并根据需要设置样式。
这是大多数字体库所做的...它们在样式表中创建伪元素并设置背景图像、对齐方式等。
假设我有一些 HTML 看起来像这样:
<div id="non-adjustable">
<a id="adjustable-a" href="example.html">
<div id="adjustable-div">Button</div>
</a>
</div>
然后我有一个样式表,其中包含一些我想添加到 #non-adjustable
div 的精彩动画。
Limitations/Requirements:
- 我无法编辑
#non-adjustable
div的HTML,所以我无法向[=]添加class 50=]. - 我可以编辑
#non-adjustable
div下的HTML(#adjustable-a
和#adjustable-div
)。 - 我可以编辑CSS但我不能从动画样式表中获取样式(我只能使用样式表中的classes) .
基本上,如果这是一件事,我希望能够做到这一点:
<style type="text/css">
#non-adjustable(.fantastic-animation) {
/*Other Declarations*/
}
</style>
但这要么不起作用,要么我做错了。还有人有其他想法吗?
您可以使用 :before 和 :after 伪元素并根据需要设置样式。
这是大多数字体库所做的...它们在样式表中创建伪元素并设置背景图像、对齐方式等。