Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    hero9989
    hero9989's Avatar
    Guest

    HTML - how do i create a href that increases/decreases the font size within the page?

    I'm currently doing an assignment in college, I want to make the web page accessible to people with visual impairments so I want to provide a link to increase the font size, then a link next to it to change it back.
    I'd like specific code if possible

  2. #2
    3726
    3726's Avatar
    Guest
    Can't use direct HTML, you need javascript



    var min=8;
    var max=18;
    function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for(i=0;i<p.length;i++) {
    if(p[i].style.fontSize) {
    var s = parseInt(p[i].style.fontSize.replace("px",""));
    } else {
    var s = 12;
    }
    if(s!=max) {
    s += 1;
    }
    p[i].style.fontSize = s+"px"
    }
    }
    function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for(i=0;i<p.length;i++) {
    if(p[i].style.fontSize) {
    var s = parseInt(p[i].style.fontSize.replace("px",""));
    } else {
    var s = 12;
    }
    if(s!=min) {
    s -= 1;
    }
    p[i].style.fontSize = s+"px"
    }
    }


    Usage

    Include the above code in your page (either by placing it within the head section or placing it in an external js file and importing it). You can then call the increase and decrease font size functions like below.

    <a href="javascript:decreaseFontSize();">-</a>
    <a href="javascript:increaseFontSize();">+</a>

  3. #3
    zeplinepoponetris
    zeplinepoponetris's Avatar
    Guest
    Use a stylesheet to define how fonts look on your page, then make another stylesheet with bigger fonts. Have one link use the small font stylesheet and the other use a big font stylesheet. You can do this with one PHP page, just have one link be to:
    yourpage?big=0
    and the other to:
    yourpage?big=1

    Then in the header have some PHP that says...
    if big=0 then use small.css
    if big=1 then use big.css
    Hope that helps.

    Although, making a site that uses proper and CSS-friendly HTML allows the visitor to resize it with ease themselves with their browser or reading software.


    Edit:
    Many people are recommending that you use JavaScript for this, but the person could have JavaScript disabled (probably unlikely, but still possible). JavaScript isn't really a "clean" method to do something like this either, plus it overcomplicated things and forces the visitors computer to do more work. With the PHP+HTML+CSS you are sending the user a plain old HTML page with a CSS stylesheet.

  4. #4
    sikreto na lang...
    sikreto na lang...'s Avatar
    Guest
    javascript

 

 

Quick Reply Quick Reply

Click here to log in


What is the sum of 36 and 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. what font and font size on textedit for html?
    By noshoesonthechair in forum Discuss HTML
    Replies: 0
    Last Post: 09-18-2011, 07:00 AM
  2. Replies: 0
    Last Post: 03-05-2011, 06:47 AM
  3. Replies: 0
    Last Post: 12-18-2010, 04:55 AM
  4. Replies: 0
    Last Post: 09-09-2009, 03:01 AM
  5. Replies: 0
    Last Post: 06-12-2009, 10:37 AM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •