We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

DaveChild on 09/11/08


Tagged

accessibility


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

alvaroisorna


JavaScript Minimum Font Size


Published in: JavaScript 


Run on document load - script checks fonts are not too small and resizes to 10pt if they are.

  1. function MinimumFontSize() {
  2. // Create div with minimal content and move off-screen
  3. var XDivElement = document.createElement('div');
  4. XDivElement.setAttribute('id', 'xDiv');
  5. XDivElement.innerHTML = 'm';
  6. document.body.appendChild(XDivElement);
  7. XDivElement = document.getElementById('xDiv');
  8. XDivElement.style.border = '0';
  9. XDivElement.style.padding = '0';
  10. XDivElement.style.margin = '0';
  11. XDivElement.style.textIndent = '0';
  12. XDivElement.style.letterSpacing = '0';
  13. XDivElement.style.fontSize = '1em';
  14. XDivElement.style.position = 'absolute';
  15. XDivElement.style.marginLeft = '-1000px';
  16. // Element Created. Measure height.
  17. if (XDivElement.offsetHeight < "16") {
  18. tags = new Array ('body', 'div', 'a', 'td', 'th', 'p', 'span', 'h1', 'h2', 'h3');
  19. for (j = 0; j < tags.length; j ++) {
  20. var getbody = document.getElementsByTagName(tags[j]).item(0);
  21. if (getbody) {
  22. getbody.style.fontSize = '10pt';
  23. }
  24. }
  25. }
  26. }

Report this snippet 

You need to login to post a comment.