Possible Duplicate:
Allow users to change font size in a webpage
I have some webpages. I would like the user to click an image and have the font-sizes of all of the content on the page increase. Is this possible? If so, how?
I know that the browsers have options inside of them. Basically, I want a way to do that in the page itself.
click(function() { $("body"). css("fontSize", "120%"); }); Done.
Syntax: font-size-adjust: number|none|initial|inherit; Below are the examples that illustrates the use of font-size-adjust property.
Set Font Size Using ems The em unit of measurement refers to the font size of a parent element. If you set a font's size to 2em , the font size will be twice that of the parent element.
The way I solved this problem was to use javascript to measure the container and then set the font size in px on that container. Once that baseline is set for the container then the relative font sizing of all the content will scale correctly using em or %.
Three things to achieve this:
Specify the overall font-size in the <body>
tag. For example:
body { font-size: 100%; }
Don't use pixels to specify font-size anywhere else in the document.
p.somePara { font-size: 120%; }
p.anotherPara { font-size: 1.4em; }
Attach an event handler to this image, to adjust the font size accordingly. Using jQuery, for example:
$("#largerTextImage").click(function() {
$("body").css("fontSize", "120%");
});
Done.
If you increase the font size of a top-level element like <body>
, then that [changed] size will be inherited by its child elements (assuming that other CSS rules for those element didn't override that size with an absolute value, which would also have messed up the user's changing font size in their browser).
This article (for example) says that it describes how to change CSS values programatically.
I would say that you could switch css.
Put all your font-sizes in a separated CSS file. Then duplicate this file and change the font sizes. Then use a piece of js script to swich css files.
There are a lot of tutorials up there that explain all about it. Here's one.
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