spectre icon indicating copy to clipboard operation
spectre copied to clipboard

How can I default base font size for mobile devices?

Open mtnra opened this issue 5 years ago • 5 comments

I find the fonts on mobile devices generally small. I'm wondering how can I change them in SCSS files to be larger (and ideally relative to the screen size)?

mtnra avatar Jul 19 '20 16:07 mtnra

@mtnra You can use @media selector to change font sizes.

@media (max-width: $size-sm) {
  body {
    font-size: xxxx;
  }
}

picturepan2 avatar Jul 20 '20 02:07 picturepan2

Should I use px, em or rem in this case?

mtnra avatar Jul 20 '20 05:07 mtnra

@mtnra At least not px: https://www.24a11y.com/2019/pixels-vs-relative-units-in-css-why-its-still-a-big-deal/

kurtextrem avatar Jul 20 '20 06:07 kurtextrem

_variables.scss has font sizes defined.

$font-size: .8rem !default;
$font-size-sm: .7rem !default;
$font-size-lg: .9rem !default;

All you need to do is redefine one or all of them in your custom style sheet. Edit: Something like that:


@media (max-width: $size-sm) {
  body {
    font-size: $font-size * 0.7;
  }
}

Vectrex avatar Jul 20 '20 09:07 Vectrex

I added this to my head :

<meta name="viewport" content="width=device-width, height=device-height"/>

and it scaled perfectly all by itself. (only after trying to overwrite a lot of scss variables with mediocre results...)

You can also avoid zooming on inputs to make the phone experience better, using this :

<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, user-scalable=0;"/>

maltherd avatar Feb 14 '21 19:02 maltherd