Creates text that scales according to the viewport width.
- Use the
clamp()
CSS function to clamp the value offont-size
between1rem
and3rem
. - Use the formula
8vw - 2rem
to calculate a responsive value forfont-size
(1rem
at600px
,3rem
at1000px
).
预览
Hello World!
HTML
<p class="fluid-type">Hello World!</p>
CSS
.fluid-type {
font-size: clamp(1rem, 8vw - 2rem, 3rem);
}