Forum Moderators: not2easy

Message Too Old, No Replies

IE, EMs and screwy layout - a simple solution

font-size: 100%

         

ergophobe

4:39 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't know whether anyone else has run into this, but here's a simple solution I found to an obvious shortcoming in IE. Let's say I have the following:

#left {
width: 13em;
float: left;
}

#other {
margin-left: 13em;
}

<div id="left">
<p>some stuff that goes on the left</p>
</div>

<div id="other">
<h1>Other Stuff</h1>
<p>the rest of the stuff</p>
</div>

This will work fine in Mozilla, Firefox, and probably Opera. In IE, however, I *think* (maybe someone can confirm) it takes its font size off the first element. So the ems in "left" and "other" are not equal and the effect is not as desired and can be off be 20% or more.

If you switch to pixels or percent, it all works fine.

Now here's the trick to make IE work right

Add one more declaration to your body tag:

body {font-size: 100%;}

Now the layout looks great in IE, Mozilla and Firefox.

Tom

choster

5:02 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Owen Briggs (thenoodleincident.com) has done extensive experimentation on the question. The main problem comes from IE's distortion of sub-1em font sizes when the user has set her browser text size to smaller or smallest.

His solution is to set the reduction factor using percentage on <body>, so that body text does not need to go below 1.0em. Thus,

body {font-size: 76%}
p,li {font-size:1em}

ergophobe

5:15 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I had weird issues where when I set the <body> font-size to something other than 100%, Firefox had problems getting the boxes the same size.

Upon reflection, that doesn't make sense, but it was so. Do you know why that might be?

Tom

choster

5:31 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We haven't done all that much experimentation of our own; we develop on Firefox and IE6 on Windows. Did you also set html {font-size:100%}?

ergophobe

6:03 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I just played around with

body {font-size: some%;}

Basically, set at 100%, which is what I want anyway, it works fine in all browsers tested (basically Firefox and IE), so I pretty much quit there. But I didn't notice that percentages other than 100% threw Firefox off.

Since <body> is already the containing element for the divs in question, why would

html {font-size: 100%;}
body (font-size: 200%;}
div {font-size: 1em;}

be any different than without the html declaration at all?

SuzyUK

10:13 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep it's an IE bug and I agree with the 100% as opposed to the 76% method....

Mr Briggs ran across the solution 76%, and he liked the size of it, but in actual fact it is an IE bug and you should (if you care about users and their defaults) set it to 100% then adjust your following em's/percentages accordingly

i.e he suggests using body : 76%... but then inherited sizes are from then on based on 1em / 100% of 76%

but that means an IE (majority) user who does have their default pixel size set lower or higher than default are no longer seeing the page based on 100%, but 76%... (it's OK for most other browsers as they "zoom")

So what you could do is set the default body to 100% (as long as it's a percent value you've "squished" the bug) you can then happily use 0.76em or 76% for the rest of the text and that will apply the same to all browsers but will keep the the MS users on a par....

you can still specify your "container/wrapper" text as 76% if you so wish but you are no longer interfering with the M$ pixel default which bases itself different from everything else, it relies on 100% equalling the default pixel text size setting the user has requested. They may still not like you for setting small fonts but at least they will be able to use their text-size "smaller" or "bigger" option 'cos of the percentage body setting

oh... it's a minefield ;)

Suzy

D_Blackwell

6:40 am on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Someone else brought this up recently, and I added my own problem to it. Suzy saved us both. It was a nightmare that I probably never would figured out.
[webmasterworld.com...]

ergophobe

7:23 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I remember the beginning of that thread, but probably missed the end. I figured this must have come up before, but I couldn't find it and I guess it doesn't hurt to have it in the title of a post so it will be easier to find for the next person.

I would have to test more, but the thing that I found curious is that the layout in Firefox was disturbed by percentages other than 100%. I didn't investigate far enough to figure out why.

Tom

SuzyUK

10:53 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tom I'm trying to put together a demo for just this issue..

interesting what you say about firefox.. I will test that too..

at the minute I'm having a distinct problem with javascript styleswitchers trying to do the browsers job...
is anyone else having IE image cache/hover or a browser override problem with this?

I'm looking at mezzoblue (it'll probably be the death of me ;)), which offers both percentage fonts and a switcher but there does seem to be a conflict.. would appreciate some extra thoughts

Suzy