5 ms·
CSS Tip: An em isn't an "m", but an ex is an "x" (2012)
- g15jv2dp 2y agoWhen the website loaded, my first action was to zoom out, because the author chose a humongous font size. Somehow, this set off a chain reaction of font size changes that took a few seconds to resolve; I don't know what goes on, but zooming out lowered the size of the body text, then after a noticeable lag the size of the header, which then increased again (?) and then the font size of the body increased again (???). I have trouble believing that a website with this kind of behavior would contain a useful "CSS Tip".
- meindnoch 2y agoClearly you haven't heard about the latest CSS feature: closed-loop font size control.
- nayuki 2y agoNo joke, I've implemented closed-loop font-size control in updateTextSize(), https://www.nayuki.io/res/full-screen-clock-javascript/full-screen-clock-24hr-with-seconds.html https://www.nayuki.io/res/full-screen-clock-javascript/full-...
- meindnoch 2y agoClearly, we need automatic differentiation for DOM attributes, so that Newton-Raphson could be used in such cases.
- Jensson 2y agoIt is really fun to watch it as you zoom though! But yeah, that is the worst reaction I've seen from a page when zooming.
- tuetuopay 2y agoLikely an effect of the circular dependency of stuff. Even with javascript off it's weird, and even at 20% zoom level the font keeps growing up to something I would already consider as too large. Oh well, css sucks, but it's at least funny to look at.
- mananaysiempre 2y agoCSS is specifically designed so that are no circular dependencies (beyond a fixed number of required passes).
- AlienRobot 2y agoCan confirm. But is it a bug or is it a feature?
- CamperBob2 2y agoIf a page malfunctions in a way that 99.999% of sites don't, it's not a feature.
- lukan 2y agoOn a mobile zoom seems to work normally, but pinch-zoom is not the same as browser zoom (ctrl + mousewheel).
- echoangle 2y agoYes, mobile zoom is normally just cropping the viewport and showing only a part of the total website. Desktop browser basically adjust the font size of the root element to zoom, I think.
- lukan 2y ago"Desktop browser" zoom changes the virtual screensize. 50%zoom gets you 2 times document.body.clientWith So all the elements that refer to the screensize, will update automatically, but usually this is quite smooth. But you can listen for the event and do all kinds of things manually (and maybe too much).
- toddmorey 2y agoThere really is good info in the article. It’s less a tip and more detail on the spec that I didn’t know.
- Traubenfuchs 2y agoThe author is generally in no position to lecture anyone about css… https://imgur.com/a/uEwI5mk https://imgur.com/a/uEwI5mk
- ComputerGuru 2y agoHonestly, the typesetting on the entire page is an absolute mess.
- CamperBob2 2y agoExactly. Learning about layout from whoever created this page is like going up to Charlie Brown and asking him to teach you how to fly a kite.
- squidbeak 2y agoThe article doesn't talk about layout or design. Is there anything you object to in the information? Or is it just the 12+yr old design of a personal website you want to snipe about?
- CamperBob2 2y agoAll I'm suggesting is that the general attitude embodied by that page ("Your browser developer doesn't know how to handle zooming. Here, let me show you how it's done") seldom makes the impression the author would like to achieve. Self-awareness is important when you set out to teach others.
- ddtaylor 2y agoNow I want to see a CSS blog by Charlie Day of It's Always Sunny in Philadelphia.
- gedy 2y agoI think it's some CSS transition, not Javascript, but yeah that is really distracting..
- deleted 2y ago[deleted]
- GrantMoyer 2y agoIt's because all the font sizes in the page are relative to: html {font-size: calc(0.5vw + 1rem)} In other words, the (user configurable) browser default size plus 0.5% of the viewport width, which is kind of insane. One (intended?) side effect is that the font size grows and shrinks as you resize the browser window horizontally.
- cantSpellSober 2y agoYes, viewport units (like vw) don't always respect user settings, such as zoom levels or custom font sizes. It seems like a good idea at first (larger viewport? larger text!) but not a recommended practice.
- velcrovan 2y agoThere's a better way to do this: html { font-size: clamp(16px, 2vw, 20px); } Pick a reasonable minimum and maximum, and between them a calculated value that scales with viewport width. (You can see this in action in the sites in my bio.)
- Jabbles 2y agoI wonder whether it worked well in 2012 when the article was written?
- deleted 2y ago[deleted]
- pas 2y agofor me the linked page does not load, but here's the archived version of the experiment http://web.archive.org/web/20120226153810/http://www.ghodmode.com/experiments/emsize.html http://web.archive.org/web/20120226153810/http://www.ghodmod...
- npn 2y agoI would rather using rem for line height instead. It is easier to maintain vertical rhythm.
- cantSpellSober 2y agoYes, prefer rem. em is fraught with peril especially once you get to deeply nested elements.
- deleted 2y ago[deleted]
- lobsterthief 2y agoI mean, em and rem serve different purposes. Like let’s say you want to append a permalink icon to different headings, you can scale its size easily based on the size of the heading it’s attached to. This is when em comes in and rem makes no sense. Unless you want to keep the icon the same size regardless, in which case rem makes the most sense.
- postmodest 2y agoThe circular reference is because em and ex are relative to the font size of the surrounding context, and you need to pick a physical (or derivable-from-physical) unit for the root context. em and ex always refer to the M and x height because that's how fonts work in the old "lead type" world.
- pxeger1 2y agoAlso: 1ch is the width of ‘0’
- cantSpellSober 2y agoThere's even an "eastern" equivalent. `ic` ("ideograph count") is the width of 水 ("water" in Chinese/Japanese/Korean).
- qingcharles 2y agoThank you. This is what makes i18n hard when you're not a native of the country you're designing for and you're not reading design blogs for other cultures. That property has never shown up on any of the sites I read.
- deleted 2y ago[deleted]
- cantSpellSober 2y agoSide note: we have the `cap` unit now as well, the height of a capital letter (ignoring descenders).
- lelandfe 2y agoNice one, this was new to me. Looks like as em has rem, cap also has rcap for deriving the value from the root font.
- qup 2y ago(2012)
- deleted 2y ago[deleted]
- karaterobot 2y agoI remember seeing some video enumerating all the dozens and dozens of units CSS has now, but I'm a simple man, and I just use rems for everything.
- alwillis 2y agoThe short answer: rem is for global sizing and em is for local or component level sizing.
- runarberg 2y agoWhy would you deny your self font aware units (such as cap or ex) or inline relative units (such as ch)? Column width form example are very intuitive to see in ch units. 30-42 ch fits roughly 30-42 characters on a line and is nice to read. 120+ ch is too long and is perfect for max-inline-size of a container with a lot of body text. Specifying that in em is kind of just guessing. Then there is viewport relative units such as vw and vh and the new container relative units cqw, cqh etc. and of course %.
- alwillis 2y agoI agree with all of that; I was responding to a comment someone made about only using rems for everything. I probably posted it to the incorrect thread.
- qingcharles 2y agoEvery time a new unit is added I find a use for it almost immediately to clean up my designs and clean up my CSS. I've practically rid myself entirely of media selectors for viewport sizes.
- rickstanley 2y agoI think I saw all of them in a CSS Tricks post, but I too took the "simple" way. At first, I marvelled at the complexity of CSS units, but it didn't take long for me to tire of them. Some tricks are still useful though, like using `calc` with `v[w|h]`, `[r]em` and `%`, that yield favourable and interesting results; fortunately you only have to remember and understand a subset of units to take advantage of this.
- mrpepka 2y agoCan't help mentioning this: https://tonsky.me/blog/font-size/ https://tonsky.me/blog/font-size/
- dang 2y agoFont size is useless; let’s fix it (2021) - https://news.ycombinator.com/item?id=35929362 https://news.ycombinator.com/item?id=35929362 - May 2023 (8 comments) Let’s fix font size - https://news.ycombinator.com/item?id=26633148 https://news.ycombinator.com/item?id=26633148 - March 2021 (347 comments)
- deleted 2y ago[deleted]
- seabass 2y agoSince the definition of Em and Ex are circular, how do bowser implementers go about actually building them? Do the actual implementations differ from the spec in that regard?
- LoganDark 2y agoThey're not really circular. `1em` simply refers to the font size value. `1ex` is derived from the font size + font choice.
- deleted 2y ago[deleted]