Created
August 7, 2024 13:21
-
-
Save H-ymt/0f6fb99d4124377d8fbaa3821dad8613 to your computer and use it in GitHub Desktop.
CSS でフォントを可変させる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*, | |
::before, | |
::after { | |
--clamp-root-font-size: 16; | |
--clamp-slope: calc( | |
(var(--clamp-max) - var(--clamp-min)) / | |
(var(--clamp-viewport-max) - var(--clamp-viewport-min)) | |
); | |
--clamp-y-axis-intersection: calc( | |
var(--clamp-min) - (var(--clamp-slope) * var(--clamp-viewport-min)) | |
); | |
--clamp-preffered-value: calc( | |
var(--clamp-y-axis-intersection) * (1rem / var(--clamp-root-font-size)) + | |
(var(--clamp-slope) * 100vi) | |
); | |
--clamp: clamp( | |
calc(var(--clamp-min) * (1rem / var(--clamp-root-font-size))), | |
var(--clamp-preffered-value), | |
calc(var(--clamp-max) * (1rem / var(--clamp-root-font-size))) | |
); | |
font-size: var(--clamp); | |
} | |
body { | |
--clamp-viewport-min: 375; | |
--clamp-viewport-max: 992; | |
--clamp-min: 14; | |
--clamp-max: 16; | |
} | |
h1 { | |
font-size: var(--clamp); | |
--clamp-min: 32; | |
--clamp-max: 40; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reset.css
などでfont-size: inherit;
が指定されているものはfont-size: var(--clamp);
を逐一指定する必要がある。(カスケードレイヤー化で防げる)