With small screen size (mobile) the font size is fixed to 14px
. On really large screens, the font size is fixed to 18px
. So it can never be lower than 14px
and never higher than 18px
. The media queries take care of that.
Then we have the middle ground where I want the font size to be dynamic between 14px
and 18px
. For that I use font-size: calc(.5vw + .85em);
which works ok, but not great. I don't know how to calculate it to start from 14px
and end at 18px
between the screen width 40rem
(16 * 40) and 65rem
.
Any ideas?
.wrap {
font-size: 16px;
}
p {
font-size: calc(.5vw + .85em);
}
p:before {
content: 'Desktop: ';
opacity: .5;
}
@media screen and (min-width: 65rem) {
p {
font-size: 18px;
}
p:before {
content: 'Desktop large: ';
opacity: .5;
}
}
@media screen and (max-width: 40rem) {
p {
font-size: 14px;
}
p:before {
content: 'Mobile: ';
opacity: .5;
}
}
<div class="wrap">
<p>
text
</p>
</div>
I also added it here: https://jsfiddle.net/6ybkp7a1/6/
Example
When I'm on a screen width of 40.1rem
(just above 40rem
), I should have a font-size like 14.1px
(or whatever it may be), just above 14px
.
Set another media query for
min-width: 40rem
along with other media queries you have. That should take care of screen size in between those two screen sizes you have added.Here's the working example(JSFiddle):
You can try this. It will go gradually from
14px
to18px
.How it works?
100vw
is our screen size so it will vary from40rem
and65rem
in the needed region. Minus40rem
we will have a variation between0rem
and25rem
.25rem
is equal to(16px * 25) = 400px
. Our variation is now from0
to400px
and if we divide by100
and we add14px
we have a variation between14px
and18px
.