• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamically change font size on a website

Participant ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

Hello

I'm building a website for people which have problems with their vision. I thought I would display a function which lets the user increase (or decrease) the standard font size (which I initially will set to p.e. 1.2em). I will use a CSS file to set all other styling properties. Is there a nice example on how to realize this. I think I need to save the users choice in the session or in a cookie. But I cannot imagine yet how to access and change my CSS file or whatever the solution will be. I imagine that I will display a couple of "A"s in different sizes and the user may click on the "A" which has the size the user likes.

Thank you very much for your help.

TOPICS
Advanced techniques

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

It's so easy to increase or decrease font sizes with your browser that you might want to take advantage of it.  The keystrokes are Control-plus and Control-minus.

You could present this information in a tool tip of some sort.  Or, you could write a js function that does the same thing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

There are a few ways to do what you want, but all require javascript.

So my questions to you are:

1. Are you allowed to use javascript on the site?

2. Can you use jQuery? (I only ask because it's pretty simple to write in jquery and makes it very cross-browser compatable)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

Dear Jeff

Many thanks for your input:

1. Yes, Javascript is no problem

2. I might use jQuery but I cannot figure out on how to de- resp. increase the font. Would you have a nice and easy understandable example?

Meanwhile I checked some codes and solutions. The most of them just work on one style. I would like to have something which works on all layouting tags (h1, h2, ...., p, a etc.)

Thank you vrey much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

Perhaps too simple, but can you not just use a Session/Client variable which stores their chosen size then include a different CSS doc at the top of the page? I.e. actually create separate CSS documents either manually so you can tune them, or dynamically.

I wrote a thing once that parsed a CSS source file and looked for my custom-formatted variables such as |<graphicsdir>| and regex-replaces them with application-level variables, you could do something with that to set sizes.

Depends how complex your CSS is really.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

Encourage users to use the browser options increase (or decrease) text size... Teach a person to fish, and they'll learn how to change text on any website.  Give a person a fish, and they'll only be able to do it on yours.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

Fair point rgurganus, alas these days I find this one more appropriate:

"To design a system that is completely foolproof is to underestimate the ingenuity of complete fools"

If someone half blind and struggling to use a website, I honestly wouldn't bother trying to teach them anything as they'll just get annoyed and won't use your site. It's all about the simplicity.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 27, 2010 Sep 27, 2010

Copy link to clipboard

Copied

LATEST

True... the same goes for adding a website option to change text size.  They're more likely to find, understand, and use a function built into their browser, vs. something unique to a particular website.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation