Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to deal with font resizing on a website

I need to put some icons for font size up and font size down on a website. It has been a while since I have done this and didn't know what was the score these days. Is JQuery the preferred method to deal with this or pure CSS. Also, do I need to do anything special with my font sizes i.e use em instead of px?

Thanks in advance.

like image 554
webnoob Avatar asked Nov 24 '10 15:11

webnoob


People also ask

Why should you optimize fonts for your website?

In fact, using optimized fonts together with a prudent strategy for how they are loaded and applied to your site can help reduce total page size and improve page speed. What’s more, optimizing web fonts will improve the Core Web Vitals grades – in particular, the CLS metric.

How to modernize your website with 5 easy font and text tricks?

5 Easy Font and Text Tricks to Modernize Your Website 1 Text sizes for mobile devices#N#Since mobile devices offer much less screen space, your font sizes need to be... 2 Text color and contrast#N#To be readable, the color of your fonts must be clear and provide sufficient contrast. A lot... 3 Text spacing More ...

What is the best font size for a website?

A font size of 12px is acceptable and is a common default for email and document software like Word. Webpages, however, benefit from larger font sizes like 18px or even 20px. Before you or your developer start messing around with font sizes on your live website, it’s important to make sure it looks good.

How do I test font size changes on my website?

There’s no easier way to test font size changes on your website than by simply pressing ctrl and + on a Windows PC or command and + on a Mac, to zoom in. To zoom back out, press ctrl and - or command and -.


1 Answers

I would go about it, by setting up all units in ems. Then, it's a simple matter to scale all of it at once using a simple javascript, like so:

    $(function () {
        var fontSize = 1.1;
        $("#larger").click( 
            function () { 
                console.log("click");
                fontSize += .1;
                $("body").css("font-size", fontSize + "em"); 
            } 
        );

        $("#smaller").click( 
            function () { 
                console.log("click");
                fontSize -= .1;
                $("body").css("font-size", fontSize + "em"); 
            } 
        );
    });
like image 104
Ioannis Karadimas Avatar answered Sep 24 '22 03:09

Ioannis Karadimas