MrMime
MrMime

Reputation: 715

Simulate ctrl+/- by code

When you surf with your browser, you can increase or decrease the font dimension by pressing CTRL + + or CTRL + -.

Is there a way to simulate this operation by code (like javascript)?

I have to put a couple of button on my site to increase or decrease the size but to make it, I have to change dynamically a lot of font-size properties (BODY, INPUT, OPTIONS etc...)

Upvotes: 0

Views: 932

Answers (1)

Kos
Kos

Reputation: 72251

Don't do this. Browser zoom is a feature that:

  • may or may not be present in a browser,
  • is implemented in different ways through browsers,
  • only exists as a last-resort plumbing for bad websites.

a couple of button on my site to increase or decrease the size but to make it, I have to change dinamically a lot of font-size properties

What you really want to do is:

  • Scale your fonts in relative units (like em or %) everywhere,
  • Change document.body.style.fontSize to modify your base size (which other elements will use as their base size).

Specify the body's font size in relative units too - In this way you can also respect the user's system settings (which every decent website should do).

There's plenty of resources on CSS font scaling around. Here's one:

http://kyleschaeffer.com/best-practices/css-font-size-em-vs-px-vs-pt-vs/

Upvotes: 4

Related Questions