• 0

[CSS] Base text size + em's


Question

So I do the typical browser reset, and set my body font size to the 62.5% that we all have grown accustom to. Now I throw my page into a container, lets say #page. #page is defined with a font-size of 1.3em (to get my baseline font-size of 13px).

Now my problem is this, I want to create a bunch of CSS classes that I can use to structure set font sizes from this baseline. So say i want ".f1" to render at 1 px higher, what should I set for its font-size em? {1.1em} would be 1.1 * 13px which is 14.3px.

Is there a set library somewhere that has these numbers for set baselines? Like if I have a 12px base, what the values for .f1,.f2,.f3.. or even .fm1 (for 1 px smaller) would be?

Thanks Neowinians!

Link to comment
https://www.neowin.net/forum/topic/738278-css-base-text-size-ems/
Share on other sites

13 answers to this question

Recommended Posts

  • 0

I want the base size of my page to be 13px... I don't want to have to set a class for fonts to be of that size. Then I want classes to be able to define 14px, 15px, 16px, 12px... etc... based off of that base.

I won't set them with straight font-size: 14px; because that is a no-no in the css world... IE6 doesn't handle scaling correctly...

As for starting at 100% or 62.5% it really doesn't matter, as I want defaults to be at 13px.. but after that, without absolutely setting pixels (so I need either ems or %'s) how do you pros do it?

  • 0

Well in that case I would set the font size for body as 81.25%. That would set the base font size as 13px. Now for 14px it would be 108%. Beware that I have not tested this and you probably will run in to issues from rounding and the methods used by browsers for rounding are known to vary from browser to browser.

  • 0

Ya, I mean that seems like the best solution... just wondering if people know if these numbers are published anywhere...

Like Yahoo's User Interface utils are great for zeroing in and testing all the irregularites across browsers, so I'm just looking for a list somewhere of all these numbers since like you said, it could vary for the rounding.

  • 0

If you want pixel perfect changes you're going to need to use pixels (or possible rem's, because they're a percentage of the font-size on the root element)

Or use lots and lots of maths and leave strange percentages laying around everywhere.

<p style="font-size: 13px">13 pixels tall <span style="font-size: 1.07692308em;">14 pixels tall-ish</span></p>

And just for reference, even IE8 doesn't get the whole "scale font-sizes marked as pixels" thing right, it doesn't look like they're ever going to fix that bug (On one hand I'm surprised they can't get simple units right, yet on the other hand I'm not, and that saddens me)

Edited by The_Decryptor
  • 0

Nah, that chart's pretty useless (only the px/pt parts are useful)

<span style="font-size: 16px;"><span style="font-size: 2.0em;"><span style="font-size: 75%;">Text</span></span</span>

The text inside the inner span is 24px tall, because em's and percentages are relative to the font-size of the containing element, a chart is only valid for one element vs. it's parent element (e.g. the body tag when the html tag is set to 16px or so)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • When I say I don't see the appeal, I meant as in general, of the character within the story. I guess apart from being a foil, as mentioned, but I still feel it could probably be done a bit more...less on the nose? A bit more nuanced? Something like that. He really just felt more like a chance to cast Fillion more than anything (to me, anyway). Obviously I am aware that Guy Gardner is not exactly meant to be an *appealing* character
    • This excellent 27-inch 1440p 240Hz QD-OLED gaming monitor is way under $500 by Sayan Sen If you are on the hunt for a great gaming monitor that is under $500, then AOC has a great option today that is worth considering. The model in question is the AOC Q27G4ZD which is a 27-inch 240 Hz display based on QD-OLED (Quantum Dot OLED) and it is at just $428 making it lowest ever priced (purchase link under the specs table below). The specialty of QD-OLED is that pairs the self-emissive OLED pixels with a layer of quantum dots, converting blue OLED light into pure red and green wavelengths more efficiently than traditional color filters. The result is brighter highlights, wider color gamut, and higher color volume without sacrificing OLED’s infinite contrast and instant response. Quantum dots are also said to reduce energy loss in color conversion, while boosting luminance and vibrancy. Thanks to the excellent color reproduction alongside the contrast, this QD-OLED monitor can be used for professional photo/video editing, animations, and such as well, plus working on spreadsheets and other office docs should be a breeze too. The technical specifications of the AOC Q27G4ZD are given below: Specification Details Diagonal Screen Size 26.5 " (67.3 cm) Panel Technology Quantum Dot OLED (QD-OLED) Maximum Refresh Rate 240 Hz (DP 1.4) 144 Hz (HDMI 2.0) Response Time (GtG) 0.03 ms (GtG) Brightness (Typ.) 450 cd/m² (10 % APL) Peak Brightness (HDR) 1000 cd/m² (3 % APL) Color Gamuts RGB 100% (CIE1931) / DCI-P3 99% (CIE1976) Color Accuracy Delta E < 2 Display Colors 1.07Billion HDR Certification VESA DisplayHDR™ True Black 400 Sync Technology Adaptive-Sync Contrast Ratio 1,500,000:1 (Typical) Color Depth 10-bit Connectivity 1 × DisplayPort 1.4 2 × HDMI 2.0 1 × 3.5 mm Audio Out 4x USB 3.2 Gen1 Ergonomics Height: 130 mm Tilt: –5 ° ~ 23 ° Swivel: –30 ° ~ 30 ° Pivot: –90 ° ~ 90 ° Bezel 3-sided frameless Special Features Flicker-Free, Low Blue Mode, Gaming Modes (FPS/Racing/RTS/Gamer1–3), Shadow Control, Game Color, Dial Point, Sniper Scope, Low Input Lag Get the AOC Q27G4ZD 27" QD-OLED at the link below: AOC Q27G4ZD 27" QD OLED Gaming Monitor, 3-Year Zero-Bright-Dot: $427.69 (Sold and Shipped by Amazon US) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • But even when it says local, it is not local, they all send info back. I bet if you unplug your computer from the net, they would not work Not saying that AI can't do useful stuff, just I don't want it pushed onto me all the flipping time
    • I know I will get shot down for this, but I prefer Windows 8, take the start screen away and use a third party start menu and Windows 8 was a pretty good OS for Microsoft. It was stable and ran very smoothly on my AMD bulldozer based computer, Windows 10 ran like a dog. When I changed to a Ryzen 7 17090 CPU, I tried to keep Windows 8 on it, but MS made that difficult with pop-ups all the time to get me to change to Windows 10 and the hacks to stop it, did not work that well. I have seen for a few years now the way Windows is going, and I don't like it and with Windows 11, what I saw was happening with Windows 10 have got worse with 11, certainly now with this AI rubbish. When I was looking at updating my PC a couple of years ago, I was looking at what CPUs were available, price and if it was going to make a lot of difference to what I use the machine for. To update my Pc to would have cost me £700 or more, that is just for the CPU, memory and board, maybe get a new case, the GPU is fine for what I use it for. I waited to see what AMD was bringing out and I thought I would look at what Apple was doing with their machines, and they launched the M2 machine at around the same time as AMD launched a new gen version of their Ryzen chip. A Mac mini m2 pro was £1,300, I had saved the money up over 12 months and yes the mini was over £600 more than the parts to update the PC, but it was a complete computer. I had the money, so I thought stick it, let's go for it. I don't regret it, what I do regret is not going for Mac years ago. Saying that Apple used Intel chips and I hate intel. I will have to update the PC at some point, but I will go for a R5 and not R7 and have less memory and a cheaper motherboard as the machine is only used for a few games these days.
  • Recent Achievements

    • Week One Done
      MIghty Haul earned a badge
      Week One Done
    • One Month Later
      MIghty Haul earned a badge
      One Month Later
    • Collaborator
      KD2004 earned a badge
      Collaborator
    • One Month Later
      ataho31016 earned a badge
      One Month Later
    • One Month Later
      Delahenty Machinery earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      592
    2. 2
      Michael Scrip
      200
    3. 3
      ATLien_0
      192
    4. 4
      +FloatingFatMan
      140
    5. 5
      Xenon
      127
  • Tell a friend

    Love Neowin? Tell a friend!