I'm developing a Web page that uses different sizes for its different paragraphs, h... and so on. I'm using em sizes: font-size: 2em;, as an example. But when I change my screen resolution to a lower one, I want that size to a smaller one.
For that purpose, I tried this code:
<script>
if ( screen.width > 1600)
{
document.write('<style>#centered h1 { font-size: 2em; } </style>');
}
else if (screen.width <= 1600 && screen.width >= 1360)
{
document.write('<style>#centered h1 { font-size: 1.7em; } </style>');
}
else if (screen.width < 1360 && >= 1024)
{
document.write('<style>#centered h1 { font-size: 1.4em; } </style>');
}
else
{
document.write('<style>#centered h1 { font-size: 0.8em; } </style>');
}
</script>
First: it doesn't work...
Second: I think there should be cleaner way to do so...
So, the question is: how to use different sizes to my fonts or how to make them adjust for different resolutions?
Can anyone help please? Thanks!
However, because they are a fixed size, pixels do not size up or down. That means that fonts will be rendered smaller on a screen with higher resolution than on a lower resolution screen.
To change your display in Windows, select Start > Settings > Ease of Access > Display. To make only the text on your screen larger, adjust the slider under Make text bigger. To make everything larger, including images and apps, choose an option from the drop-down menu under Make everything bigger.
Modern computer monitors / screens leave the factory with the screen resolution set at 1024 x 768 pixels or even higher. This is to give the maximum effect for graphics, particularly for playing computer games. However this has the effect of making the text size, and icon size smaller in general use.
The font size can be set with vw (viewport) unit, which means the viewport width. The viewport is the browser window size. 1vw = 1% of viewport width. If the viewport is 50cm wide, 1vw is 0.5cm.
Select 'Display'. Select the 'Change display settings' link towards the top of the window on the left-hand side. In the 'Resolution' section, select the pull-down bar, and a slider bar should appear. Move the slider bar down to make the text larger, or move it up to make the text smaller.
html { font-size: 62.5%; }
body { font-size: 1em;}
@media (max-width: 300px) {
html { font-size: 70%; }
}
@media (min-width: 500px) {
html { font-size: 80%; }
}
@media (min-width: 700px) {
html { font-size: 120%; }
}
@media (min-width: 1200px) {
html { font-size: 200%; }
}
You want to use media queries rather than JS. Alternatively, use JS to add a class to the body then use that to target what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With