35

58 bytes of css to look great nearly everywhere

 5 years ago
source link: https://www.tuicool.com/articles/hit/BrUvuuv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

when making this website, i wanted a simple, reasonable way to make it look good on most displays. not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}

let's break this down.

max-width: 38rem

it appears that the default font size for most browsers is 16px, so 38rem is 608px. supporting 600px displays at a minimum seems reasonable.

padding: 2rem

if the display's width goes under 38rem, then this padding keeps things looking pretty good until around 256px. while this may seem optional, it actually hits two birds with one stone - the padding also provides sorely-needed top and bottom whitespace.

margin: auto

this is really all that is needed to center the page, because main is a block element under semantic html5.

a key insight: it took me a surprising number of iterations to arrive at this point. perhaps that speaks to the fact that i know nothing about "modern" web development, or, as i'm more inclined to believe, just how hard it is to keep it simple in a world of complication.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK