We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    Does anyone know the coding you would use in css stylesheets to allow the website visitor to change the font size from within their own broswer?

    My client wants to allow visitors to click on an image to increase the fontsize and click on it again to go back to the original font size.

    Is there a way to do this?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You’ll need a bit of Javascript to do that. Do a Google search, and you’ll find a ton of them.

      For example http://forum.mootools.net/topic.php?id=3308
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 21257 MODX Staff
        • 730 Posts
        Quote from: ganeshXL at Dec 03, 2007, 02:03 PM

        Doesn’t every halfway modern browser today already do that? CTRL - (minus) for minimize, CTRL + (plus) for maximize font-size (and whatever equivalent you have on Macs).
        When a client sees something somewhere on the web, or if their friend says "hey, isn’t your designer doing {{this}}", sometimes there’s no stopping that freight train. What the client wants (if they’re paying), the client shall receive wink

        @WeBe: changing font size is one thing, but make sure you understand the ramification to your layout.. You could find yourself doing extra html/css work that you didn’t bargain for if the font size change makes your template explode.
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 34162
          • 1 Posts
          Thank you for your quick replies smiley

          @sottwell: I know there are javascripts to do that, but I hoped it could be done by css, or even by Modx (a tv perhaps?)

          @netProphET: the font size should be increased from 12px to 14px, just to be better readable for older people, which is a must for this site. I know it has its consequences for the template, but it can be controlled.
            • 21257 MODX Staff
            • 730 Posts
            Actually, there are a few ways to achieve what you want without using javascript.

            One way would involve moving the CSS that controls font size into your template, making a simple little snippet to remember the desired font size and output it as a placeholder, then using that placeholder in the CSS in your template.

            To illustrate, the template could start something like this...
            [[fontsizer? ]]
            <html>
             <head>
              <style>
               body {
                font-size:[+fontsize+]px;
              }
               </style>
             </head>
             ...
            


            Then the fontsizer snippet would just need to read the font size value you want (I’m using a querystring parameter just to make it easy), remember it in the php session, and set a placeholder.
            <?php
            /**
             * fontsizer snippet
             */
            $fontsize = '12'; //the default value
            
            // ... see if the querystring is telling us the font size
            if(isset($_GET['fontsize']) && is_numeric($_GET['fontsize'])) {
              $fontsize = $_GET['fontsize'];
              $_SESSION['fontsize'] = $fontsize;
            
            // ... if the querystring isn't set, see if there's a value set in the php session
            } elseif(isset($_SESSION['fontsize']) && is_numeric($_SESSION['fontsize'])) {
              $fontsize = $_SESSION['fontsize'];
            }
            $modx->setPlaceholder('fontsize', $fontsize);
            return '';
            


            Then from some link on your page, you just need to link the page to itself, plus the font size.
            <a href="[~[*id*]~]?fontsize=12">regular</a> | <a href="[~[*id*]~]?fontsize=14">large</a>
            


            I haven’t tried the above code.. but I hope it helps get you going.
              Mike Schell
              Lead Developer, MODX Cloud
              Email: [email protected]
              GitHub: https://github.com/netProphET/
              Twitter: @mkschell
              • 21496
              • 225 Posts
              Quote from: WeBe at Dec 03, 2007, 04:36 PM

              @netProphET: the font size should be increased from 12px to 14px, just to be better readable for older people, which is a must for this site. I know it has its consequences for the template, but it can be controlled.

              The irony is that people with impaired eyesight (or other disabilities) learn how to cope with that and know how to make pages readable for them. The others have to be educated.

              I believe sometimes it’s better to educate people than just to fulfill their wishes. Even if they would pay for it.

              I wonder how seen from an usability point of view, a good implementation of a feature like that looks like. Maybe with something like this:

              [glow=red,2,300]Do you want to read the rest of the page in letters as big as these? Please click here![/glow]

              EDIT: actually I wanted to make the font size bigger here, but it does not work ...

              The technical aspects are only one side. If you can, do some usability tests with your target audience, and see if they find the function and make use of it as expected. In order for it to work, I think it has to be made pretty dominant.

              Can anyone provide examples for good implementations of that feature?
                René
                • 34162
                • 1 Posts
                @netProphET: your solution works like a sharm! laugh

                Only had to change the last command to:
                return '';


                Otherwise I got a ’1’ displayed in my design.

                Thank you for helping out here!
                  • 23019
                  • 27 Posts
                  I don’t know if it’s normal, but this code only works for me when the page is uncacheable.

                  Is there any solution to this? I say it beacuse doing the whole site uncacheable will make it slow, it isn’t?

                  Thanks smiley
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    It should work when the snippet is called uncached [!...!]
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 23019
                      • 27 Posts
                      Quote from: sottwell at Dec 06, 2007, 05:15 AM

                      It should work when the snippet is called uncached [!...!]

                      I’ve already tried but when the snippet call is in this way simply it doesn’t work, the whole snippet. The placeholder is ignored in the css code.