Return to Snippet

Revision: 8292
at September 11, 2008 11:20 by DaveChild


Initial Code
function MinimumFontSize() {
    // Create div with minimal content and move off-screen
    var XDivElement = document.createElement('div');
    XDivElement.setAttribute('id', 'xDiv');
    XDivElement.innerHTML = 'm';
    document.body.appendChild(XDivElement);
    XDivElement = document.getElementById('xDiv');
    XDivElement.style.border = '0';
    XDivElement.style.padding = '0';
    XDivElement.style.margin = '0';
    XDivElement.style.textIndent = '0';
    XDivElement.style.letterSpacing = '0';
    XDivElement.style.fontSize = '1em';
    XDivElement.style.position = 'absolute';
    XDivElement.style.marginLeft = '-1000px';
    // Element Created. Measure height.
    if (XDivElement.offsetHeight < "16") {
        tags = new Array ('body', 'div', 'a', 'td', 'th', 'p', 'span', 'h1', 'h2', 'h3');
        for (j = 0; j < tags.length; j ++) { 
            var getbody = document.getElementsByTagName(tags[j]).item(0); 
            if (getbody) {
                getbody.style.fontSize = '10pt';
            }
        }
    }
}

Initial URL

                                

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

Initial Title
JavaScript Minimum Font Size

Initial Tags

                                

Initial Language
JavaScript