3

On a web page that does not contain a viewport meta tag, most mobile browsers will "boost" some or all of the fonts on the page to a size larger than what the css specifies. On mobile Safari, for instance, a specified size of 7px will be boosted to something like 12px.

You can read out the boosted value by using getComputedStyle. My question is, is there a reliable way to read out the unboosted value? I.e. if the font is boosted to 12, I want to know that it started out at 7.

dave mankoff
  • 17,379
  • 7
  • 50
  • 64
  • By specified style are you refering to the actual style that is either specified in the linked stylesheet or inside style tags? – Sai Apr 02 '15 at 21:51
  • Yup. I want the raw style, as specified in the stylesheet/style tag/inline, etc., vs. what the browser ends up rendering. – dave mankoff Apr 03 '15 at 15:55

2 Answers2

0

Webkit has a deprecated function to get all stylesheet rules for an element: window.getMatchedCSSRules(<<element>>). You could use that to get the list of rules and loop through them to print or process the properties of each however you like. You would also need to consider the style attribute of the element.

To handle your font-size scenario, I imagine the best approach would be to get all the rules that apply to the element, order them by priority (remembering to factor in the style attribute and !important flags, and then pick out the value.

This isn't exactly reliable though, since it's a Webkit function and it's on its way out. There's a bunch of discussion here about how to fish out rules. Once you have the rules for an element, it's just a matter of picking out the specific information you need.

Community
  • 1
  • 1
mirichan
  • 1,370
  • 1
  • 12
  • 25
0

Just a quick answer here. In short: you can't get specified styles with today's API's. I was able to solve my specific problem by temporarily turning off font-boosting by using text-size-adjust (prefixed with -webkit- for Safari).

dave mankoff
  • 17,379
  • 7
  • 50
  • 64