有没有办法将 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:

  1. 无法编辑#non-adjustablediv的HTML,所以我无法向[=]添加class 50=].
  2. 可以编辑#non-adjustablediv下的HTML(#adjustable-a#adjustable-div)。
  3. 可以编辑CSS但我不能从动画样式表中获取样式(我只能使用样式表中的classes) .

基本上,如果这是一件事,我希望能够做到这一点:

 <style type="text/css">
      #non-adjustable(.fantastic-animation) {
           /*Other Declarations*/
      }
 </style>

但这要么不起作用,要么我做错了。还有人有其他想法吗?

您可以使用 :before 和 :after 伪元素并根据需要设置样式。

http://www.smashingmagazine.com/2011/07/13/learning-to-use-the-before-and-after-pseudo-elements-in-css/

这是大多数字体库所做的...它们在样式表中创建伪元素并设置背景图像、对齐方式等。