In my code, I use css which sets the HTML font-size
property to different percentages according to the screen width so any rem
values are changed accordingly but now my font sizes are all messed up I’ve tried using css reset and setting body font-size
but that doesn’t seem to work.
Here is a snippet:
@media only screen and (max-width:75em) {
html {
font-size: 59%
}
}
@media only screen and (max-width:56.25em) {
html {
font-size: 56%
}
}
@media only screen and (min-width:112.5em) {
html {
font-size: 65%
}
}
body {
box-sizing: border-box;
position: relative;
line-height: 1.5;
font-family: sans-serif;
font-family: 'Source Sans Pro', sans-serif;
padding-top: 3.8rem;
width: 100vw;
font-size: 100%;
}
Note that this is a svelte component imported using slot tag
2
Answers
I tried your code in the Google Chrome browser and saw that it works correctly https://codepen.io/agokselb/pen/JjVORBE . Could you please try the above code? Maybe the browser, classes are not overwriting or do not support the em unit.
Not sure why you would want to use the html tag to change the font-size globally. Why not use component-based font-sizes instead? Also I would suggest you to change the font-size within the body, not within the html.
One reason could be that you are not setting a default value to fall-back on to.
I suggest you do this:
Even if the final semicolon on CSS are not needed, it is recommended that you are considering to place them either way to prevent further bugs and issues (which I’m guessing might also be happening here, because you are using Svelte).
Please elaborate your requirements, so we can provide further assistance. I don’t quite understand which
rem
values you want to change, if you’re working with%
on the@media
queries. If you want to change therem
values dynamically depending on the window size, you would need to define css variables for various text sizes and change the value of it using the@media
queries, instead of changing font-size directly.