Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Last active October 19, 2022 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayamflow/f2cacfb98bf7a2fb6d700e863884bb4c to your computer and use it in GitHub Desktop.
Save ayamflow/f2cacfb98bf7a2fb6d700e863884bb4c to your computer and use it in GitHub Desktop.
Mobile responsive components
  1. Size components in px from mockup size
width: 300px;
height: 240px;
  1. in resize, change component fontSize from default (16px) to ratio of "device size / mockup size")
el.style.fontSize = Math.min(width, height) / 360 * 16 + 'px'
  1. change components from px to em
width: 300px / 16px * 1em;
height: 240px / 16px * 1em;

or with sass functions:

@function em($px) {
    @return $px / 16px * 1em;
}

width: em(300px);
height: em(240px);

Components will now scale proportionnally with device size, compared to the mockup size

Used in: http://swissarmyman.com and others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment