it is working, and it's working correctly. I do understand, however, that it's not doing what you expect.
Also, the way I described "setting everything to 100%" may have been a little misleading; and maybe not quite what you were asking about.
one of the benefits of ems is that they inherit.
say you have all your main content, and a smaller "note" section off to one side:
HTML Code:
<div id="main_content">
<h1>My content!</h1>
<p>I'm writing lots of stuff here.
Leave me alone so I can finish my website.
Blah blah blah...</p>
</div>
<div id="notes">
<h1>Notes:</h1>
<p>What I really meant by "blah blah blah" was,
<i>you're a wonderful person and I value your opinions</i>.</p>
</div>
You want the "notes" to have a smaller font-size than the main content. Two approaches:
Code:
h1{ font-size: 24px; }
p{ font-size: 16px; }
/* special rules for your "notes" */
/* calculate 3/4 size for all elements */
#notes h1{ font-size: 18px; }
#notes p{ font-size: 12px; }
Obviously, the more content in #main_content or #notes, the larger and more complicated and error-prone our css will become, because we have to define each rule individually.
This is the problem that ems are intended to solve:
Code:
h1{ font-size: 1.5em; }
p{ font-size: 1em; }
#notes{ font-size: .75em; }
all done. fewer lines of code, same result*, all applied to #notes automatically.
*most desktop browsers default to "medium" font-size - usually 16px.
If you notice, the reason this works is because I'm applying different sizes to specific containers (only where I actually want the font-size to change, not on generic elements), and I'm not "nesting" anything. In other words, I'm not doing this:
Code:
div{ font-size: 1.5em; }
HTML Code:
<div>this
<div>text
<div>keeps
<div>getting
<div>BIGGER!!!!</div>
</div>
</div>
</div>
</div>
You're trying to use "em" as a specific, always-the-same font size. It's not. It's more like percentages. It's based on the font-size of the parent: the parent element font-size is "1em" for the child element's font-size.
To do what you're trying to do, you would have to use px values (and/or rems). In general, however, this should be avoided for the reasons I described above and in my previous post.
About the only time I use pixel font-sizes is when I absolutely need something to always be the same size - for example, text that is related to an image, or a nav menu that is limited to a certain size in order to display correctly.
Bookmarks