What html code do I use to offer viewers of my webpage different text sizes?
What html code do I use to offer viewers text size options (ex., sm, med, lg text)?
Collapse
X
-
Tags: None
-
Is your web page static or is it dynamically created by a server side script?
Are you permitted to use JavaScript in your solution.
Typically you would use CSS to set the font-size for your web page.
For example, if you want your page's content to be small font size you might have the following css:
For medium:Code:body{ font-size:small; }
For large:Code:body{ font-size:medium; }
Now the thing is that you need to apply the CSS to your page when the user indicates that they want to change the font size.Code:body{ font-size:large; }
You could submit the page to sever-side code which would apply the corresponding font-size-css style to the value that the user selected.
Or you could use JavaScrpt to change the font-size css style....
Or you could redirect the user to a page that is exactly the same but uses the font-size style that the user selected.
-Frinny -
This is a solution using jQuery, and my preferable way of doing it (because it's small and fast and everyone on the Internet already have jQuery in their cache).
CSS-code:
JavaScript-code:Code:.smalltext { font-size: small; } .mediumtext { font-size: medium; } .largetext { font-size: large; }
HTML-code (snippet):Code:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"> <script type="text/javascript"> $(#small).onclick(function(){${'body').addClass('smalltext');}); $(#medium).onclick(function(){${'body').addClass('mediumtext');}); $(#large).onclick(function(){${'body').addClass('largetext');}); </script>
Code:<a href="#" id="small" class="smalltext">aA</a> <a href="#" id="medium" class="mediumtext">aA</a> <a href="#" id="large" class="largetexttext">aA</a>
Comment
Comment