开发者

How do I add a css class in a GM-script?

I found开发者_开发技巧 out that this is the way to style all images on a site.

GM_addStyle("img { border: 3px dotted green;background-color: red; }");

How do I style just a few? Is there a way to add a class to the GM_addStyle so that I can call this class later with jQuery like .addClass('myClass')?

Thank you in advance for your help and time for answering the question.


Yes,

GM_addStyle(".myClass { border: 3px dotted green;background-color: red; }");

will create a class style that you can then add via jQuery's .addClass('myClass').

.
Note: you can add more than 1 style with each GM_addStyle statement, too. Like:

GM_addStyle
(
   '.ClearFloats                                            \
    {                                                       \
        clear:              both;                           \
    }                                                       \
    .HideIt                                                 \
    {                                                       \
        display:            none;                           \
    }                                                       \
    .StayOpaque                                             \
    {                                                       \
        opacity:            1 !important;                   \
    }                                                       \
   '
);

etc.


GM_addStyle((<><![CDATA[
    .myClass {
        border: 3px dotted green;
        background-color: red;
    }
]]></>).toString());

This way you don't need to end each line with \

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜