S
S
Sergey Goryachev2017-04-13 19:21:02
css
Sergey Goryachev, 2017-04-13 19:21:02

Px to Rem how to use?

Actually, I tried two gallp plugins today, but they didn’t take off for me.
Maybe someone already uses such a bunch, share the task.
How would it be more convenient to typeset in PX, but I want to achieve a better display of the site.
Yes, and it took recently to make a version for the visually impaired and the site collapsed ugly.
In html, I usually have 16px or 14px.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2017-04-13
@webirus

Well, here's the basic outline.

$root-font-size: 16px;

@function rem($size) {
  @return $size / $root-font-size * 1rem;
}

html {
  font-size: ($root-font-size / 16px) * 100%;
}

.some-block {
  font-size: rem(24px);
}

The function can be replaced with a mixin, whichever is more convenient. It is easier to make a pixel fallback with a mixin (only IE8 is relevant).
You can use mixins from vertical-rhytm as part of a compass.
You can look at other libraries. Lots of options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question