Here's a proof of concept, using jQuery, for brevity and clarity.
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<title>Font size with jQuery</title>
</head>
<body>
<a href="#" id="largerText">A+</a>
|
<a href="#" id="smallerText">A-</a>
<p>E tu, "Lorem ipsum" ?!</p>
<script>
$("#largerText").click(function() {
$("body, input, select, textarea, button").css("font-size", (parseInt($("body").css("fontSize")) * 1.1) + "px");
});
$("#smallerText").click(function() {
$("body, input, select, textarea, button").css("font-size", (parseInt($("body").css("fontSize")) * 0.9) + "px");
});
</script>
</body>
</html>
It works by multiplying the body font size by a 1.1 factor for larger text and by a 0.9 factor for smaller text.
There are a number of form elements that are not affected by the body font size value. That's why those are listed along with the body element in the jQuery multiple selector: input, select, textarea, button. This means, of course, you should take care of them in more detail than I did above.
The main issue is that you have to use relative values for the elements affected by the body font size changes: em or %. Using px font sizes for them it means they will not inherit the font size anymore.
Bookmarks