Posted By

DaveChild on 09/11/08


Tagged

accessibility


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

alvaroisorna
knibals


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.