0
votes

Is there any way to access the browser's default font size setting from within Sass but not using REMs?

The situation: I'm setting up Sass functions and mixins that will let me work with a rem-based vertical baseline grid (vertical rhythm, if you prefer). Using REMs I can set the 'unit' my vertical grid as a multiple — say x1.5 — of the browser's base (default) font size, since the default is what will be applied to the HTML tag, from which REMs are derived. If the user adjusts the browsers default text size then the vertical grid will scale accordingly, but the vertical height of a single 'unit' of the vertical grid is tied to the browser default, not to the size of a particular piece of text, or the font-size setting of the container element, as might be the case if I used ems or a unitless line-height value. So that's fine.

Of course, for older versions of IE I need to set a pixel fallback and here the problem lies. I want the vertical grid's 'unit' value to be tied to the root element's font size, as above, but the only way I can see to do that (if REMs are not supported) is to explicitly specify the 'base' font-size (eg. 16px) as a variable. Any other relative unit (ems, percentages) will take its value from the parent context, not from the root element. But as soon as I specify the font size in this way I am making an assumption, and potentially overriding the user's preferences, something that I'd rather not do.

So I wondered if there is a command in Sass to access or reference the browser's default font size without invoking the REM unit?

1
SASS compiles to CSS, so it can't do anything that CSS can't.SLaks
I'd say that SASS can do lots of things that CSS can't -- but I understand what you mean. And you're right, of course. SASS is compiled to pure CSS before it reaches the browser, so even if a programming hook that could extract a browser's default setting existed, it would be no use because the fancy, 'programmable', prior-to-compilation aspects of SASS never actually encounter the browser at all. Only the end result pure css does that.RickL

1 Answers

1
votes

I'd failed to think it through. As stated in my comment above, the issue is null and void. SASS is compiled to pure CSS before it ever reaches the browser, so even if a programming hook that could somehow extract a browser's default setting existed, it would be no use. Because the fancy, 'programmable', prior-to-compilation aspects of SASS never actually encounter the browser at all. Only the end result pure css does that.

My question, now that I think about it more clearly, was akin to asking whether there is any way for the tv factory to automatically adjust the tv's settings, prior to me ever buying it, according to my viewing preferences. Clearly what I was asking is nonsense.