Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28656

Re: Change font size in multiple classes

Path csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Change font size in multiple classes
Date Mon, 07 Sep 2015 03:33:51 +0200
Organization PointedEars Software (PES)
Lines 71
Message-ID <7102025.hhzk33F4p0@PointedEars.de> (permalink)
References <l8-dnaGgOJ9fWXrInZ2dnUU7-VOdnZ2d@westnet.com.au> <font-size-20150903062100@ram.dialup.fu-berlin.de> <XnsA50A6E8843ADDeejj99@194.109.6.166> <cvOdnTKEy9vIvnXInZ2dnUU7-amdnZ2d@westnet.com.au> <ms9ks0$mgb$1@dont-email.me> <XnsA50AA7739D4CFeejj99@194.109.6.166> <ms9lfo$otq$1@dont-email.me> <XnsA50AA989965EAeejj99@194.109.6.166> <SoydnUOUHLpkrXTInZ2dnUU7-WmdnZ2d@westnet.com.au>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1441589840 2013 eJwVxsEBwCAIA8CVRAngOCJk/xFaX3dYJnZdDaYgmD5dubv+IynmcbVO+YaMfuQaaEHklGR8J/wRRw== (7 Sep 2015 01:37:20 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Mon, 7 Sep 2015 01:37:20 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwFwQkBwDAIA0BL4wktcggU/xJ2BwuJPh4Ix2JpU+16H4fCj5b58HiWqmxGm2xUYS0rx4WrA2n7qEjr+wOL4Bab
Cancel-Lock sha1:cberuT14PbAmp3jgO+zgw1Ggob8=
X-NNTP-Posting-Host eJwFwYEBACAEBMCVyPMZJ8r+I3TnFhpNhAd8fHLoS1aeNtFtANHnUiv52jQ571aXwOQSe30KxBCh
Xref csiph.com comp.lang.javascript:28656

Show key headers only | View raw


Andrew Poulos wrote:

> I'm now trying this and it seems to be ok (not working in IE 8):
> 
> 
> var i,
>      j,
>      len,
>      rules;
> 
> for (j = 0; j < document.styleSheets.length; j++) {

The number of stylesheets does not change during the loop, does it?

>    rules = document.styleSheets[j].cssRules;

(I will forever wonder why people find this ripping apart of declaration and 
initialization, and the duplication of identifiers, better than the the 
compact variant, but anyhow:)

This does not work in IE 8 because earlier MSHTMLs do not support the 
“cssRules” property, but the “rules” property instead.

>    len = rules.length;
  
>    for (i = 0; i < len; i++) {
>      if ( /font-size/.test(rules[i].cssText) ) {

You are doing pattern matching on a serialization of what was already 
parsed.  It should be more efficient to determine whether the “font-size” 
property was declared instead.

Apparently the short-hand property equals the empty string, and the 
getPropertyValue() method returns “null”, in Blink, if the property has not 
been declared; both DOM 2 Style CSS and CSSOM specify it should be the empty 
string.  However, both values are type-converted to “false”.

<http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleDeclaration>
<http://www.w3.org/TR/cssom/#dom-cssstyledeclaration-getpropertyvalue>

>        rules[i].style.fontSize =
>          (parseInt(rules[i].style.fontSize, 10) / 16) + "em";

The value of the font-size property is a CSS /length/, consisting of a 
*floating-point value* and a unit (that is optional if the value is zero).
Use parseFloat() instead.

>      }
>    }
> }
> 
> document.body.style.fontSize = "100%";
> 
> 
> I search for font-size rules and then convert any to EMs based on 16
> pixels equals 1 em (the app only ever publishes font sizes in pixels).

“16px” equals “1em” only if the user or you, for your document, have 16px 
set as base font-size, and an ancestor element has not set a different font-
size (“em” is a *relative* unit, whose value equals the one-hundredth part 
of a “%” value; cf. “rem”).  (Since you are overriding the original font-
size value of the “body” element, you would need to set the font-size of the 
“html” element to “16px”.  But do that only as a last resort.)

<http://www.w3.org/TR/css3-values/#lengths>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-03 13:55 +1000
  Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-03 10:09 +0200
  Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-03 10:51 +0200
    Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-03 20:39 +1000
      Re: Change font size in multiple classes Jake Jarvis <pig_in_shoes@yahoo.com> - 2015-09-03 16:20 +0200
        Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-03 16:27 +0200
          Re: Change font size in multiple classes Jake Jarvis <pig_in_shoes@yahoo.com> - 2015-09-03 16:30 +0200
            Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-03 16:39 +0200
              Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-04 15:49 +1000
                Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-04 09:37 +0200
                Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-04 18:11 +1000
                Re: Change font size in multiple classes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-07 03:33 +0200
      Re: Change font size in multiple classes "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-03 16:24 +0200
  Re: Change font size in multiple classes Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> - 2015-09-05 20:49 +0100
    Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-06 19:30 +1000
      Re: Change font size in multiple classes Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> - 2015-09-07 20:27 +0100
  Re: Change font size in multiple classes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-06 14:07 +0200
    Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-07 09:53 +1000
      Re: Change font size in multiple classes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-07 20:35 +0200
        Re: Change font size in multiple classes Andrew Poulos <ap_prog@hotmail.com> - 2015-09-08 14:18 +1000
          Re: Change font size in multiple classes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-09 04:51 +0200

csiph-web