How to replace all "font-size: 14px;" patterns by "font-size: 16px;" ?

292 views
Skip to first unread message

Ben

unread,
Nov 23, 2011, 2:58:08 AM11/23/11
to greasemonkey-users
Assume I want to replace in all web pages from domain

http://www.aabbccdd.com

the CSS entries :

"font-size: 14px;" by "font-size: 16px;"
and
"font-height: 23px;" by "font-height: 18px;"

How exactly can I achieve this with GM?

Ben

Sam L

unread,
Nov 23, 2011, 9:55:51 AM11/23/11
to greasemon...@googlegroups.com
GM_addStyle("body{font-size: 16px; !important;}");

you probably need to select specific elements in place of body and add
more than one rule

try discovering which rule defined the font style in the first place
and use that selector.

> --
> You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
> To post to this group, send email to greasemon...@googlegroups.com.
> To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
>
>

Ben

unread,
Nov 23, 2011, 11:54:24 AM11/23/11
to greasemonkey-users
Thank you.

Does GM_addstyle() also OVERWRITE existing rules? or does it only add/
append new rules?
In other words is there a similar GM_modifyStyle() function?

The detailed (final) rule look like:

.articleContent .module .text p {
font-size: 16px;
line-height: 18px;
}

Can I write then:

GM_addStyle("articleContent .module .text p { font-size: 16px; line-
height: 18px; }");

Ben

Sam L

unread,
Nov 23, 2011, 11:59:52 AM11/23/11
to greasemon...@googlegroups.com
It only appends rules, and it will automatically over-ride rules that
are already defined (the latest rule always has priority)

I notice I typed the important keyword wrong:

GM_addStyle("body{font-size:16px !important;}");

there should be no semicolon

http://webdesign.about.com/od/css/f/blcssfaqimportn.htm

Anthony Lieuallen

unread,
Nov 23, 2011, 3:16:45 PM11/23/11
to greasemon...@googlegroups.com
On 2011-11-23 11:59 AM, Sam L wrote:
> It only appends rules, and it will automatically over-ride rules that
> are already defined (the latest rule always has priority)

That statement is incorrect. Read about "specificity" in CSS:
http://www.w3.org/TR/CSS2/cascade.html#specificity

(The "!important" keyword is just the highest specificity single
element. Except for being in the style attribute, rather than in a
sheet. Order is the lowest contributing element to specificity.)

> I notice I typed the important keyword wrong ... there should be no
semicolon

That also isn't strictly true. There definitely _should_ be, if there's
another declaration. With only one it's optional, but "should be no" is
going too far in my book.

Sam L

unread,
Nov 24, 2011, 4:34:10 PM11/24/11
to greasemon...@googlegroups.com
I had originally placed a semicolon between the rule; and
!important... which I think makes the !important apply to nothing:

GM_addStyle("body{font-size: 16px; !important;}");

for whatever reason even though I removed it in my reply, it still
shown on my screen as quoted text.

My incorrect statement, what I meant to say that the same exact
selector appended later will over-ride any rules that were defined by
that selector earlier.

It doesn't append rules so much as it appends selectors (that may
contain rules which may over-ride previous rules defined by that
selector).

Calling the selector and containing statements a rule seems all too
common, but strictly incorrect.

And Thank You for the link about specificity! Very interesting to
have a definitive knowledge other than trial and error. It makes
perfect sense given what I've experienced.

Anthony Lieuallen

unread,
Nov 25, 2011, 3:53:54 PM11/25/11
to greasemon...@googlegroups.com
On 2011-11-24 4:34 PM, Sam L wrote:
> I had originally placed a semicolon between the rule; and
> !important... which I think makes the !important apply to nothing:

Yes.

> My incorrect statement, what I meant to say that the same exact
> selector appended later will over-ride any rules that were defined by
> that selector earlier.

That is correct.

> And Thank You for the link about specificity! Very interesting to
> have a definitive knowledge other than trial and error. It makes
> perfect sense given what I've experienced.

Yeah, my mind was a little blown the first time I learned that too.
Obvious in hindsight but mysterious until you know that detail.

Reply all
Reply to author
Forward
0 new messages