views:

862

answers:

3

I want to provide a feature on my website to let users increase and decrease the font size by clicking on some stuff (like + and - image etc). However I also want:

  • make sure that when the font size is increased, my website layout doesn't get messed up
  • test the scenario out on my machine to make sure about the point above

I think what I want is a solution that is independent of the browsers font size and machines font size otherwise i would have no way of testing and controlling the results

in my web application, i haven't hard coded font sizes but in some place i have specified text boxes length like width = 50px which i think needs to be changed..so what unit should i use?

i am thinking of using themes and defining the font sizes of labels and text boxes as small, smaller, bigger etc ..not sure if that will work?


Update: I asked the question on another forum as well: http://forums.asp.net/t/1453926.aspx

Basically, from all the answers, I gathered that there are two approaches:

  1. Use em and body font size: body { font-size: 62.5%; } p { font-size: 1.2em; }

and when you have to increase/decrease font size, simply increase/decrease the body font size percentage

  1. Use absolute font sizes: css defines a range (7) of font sizes from xx-small to xx-large so you can define font-size: small in css..

i found a good article on these font sizes at: http://meyerweb.com/eric/articles/webrev/199908a.html

however none of these two options is what i was looking for. I was looking for setting absolute sizes in the real sense so if i set font-size:large, and then i increase the browser size, font sizes should remain same..right now even with these"absolute font sizes" its dependent on current browsers font size. Any help????

+1  A: 

I would use jQuery to do this. This question wasn't exactly the same, but the highlighted answer is very close to what you want to achieve:

http://stackoverflow.com/questions/891980/change-font-size-in-a-webpage/892031

This one is also quite good: http://webrocket.ulmb.com/ability, although the demo is a little pants

Paul
thanks..but the answer for that question suggest :body{ font-size: 62.5%;}does that mean make it 62% of the size configured in the browser or at the OS level..in that case, the problem is that i cant control and test it..i mean one users default font size could be 20 and for someone else it can be 12..so...
But without defining actual font sizes in the css, the only thing you can use is percentages. If you were to set all of the fonts at "normal" level to be a particular pixel size, then you could get away with defining classes such as smaller, small, normal, big as actual pixel sizes. Otherwise, percentages (or maybe em's) are the only way of achieving this.
Paul
A: 

jQuery, see Easy text resizer with jQuery

+1  A: 

You might want to look into some surveys to see if this is a desired feature. Most people I know will use their web browser's built in functionality to manipulate font size. Throughout my own testing and development on various sites, most clients ignore font-size controls on websites. Might save you some time in the long run :)

If you find you actually implement this, the biggest concern is to make sure that your font-sizes are increased in a balanced matter, and that your layout and css design patters are "fluid" and "expandable". This is actually sort of hard, because if the site design is a fixed-width layout, then you may run into problems with the content not being able to fit anymore, which can be pretty disheartening with what you're trying to accomplish.

If it's not though, then again just make sure to maintain a balance between elements and their font-sizes. Personally though, I would leave the font-changes up to the web browser. Most browsers are pretty good about manipulating your layouts on their own.

David Anderson
thanks..that's exactly my concern .. i want to make sure if the user increase the font sizes through the browser, the web application (consisting of bunch of forms) doesnt get messed up...how do i do that and i do i know my website is fluid and expandable..i havent hard coded any sizes or font sizes in my web application