By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,738 Members | 1,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,738 IT Pros & Developers. It's quick & easy.

ex vs. em vs. px vs. % vs. in.

P: n/a
Hello All,

I am looking for a for a good tutorial on font size definitions in a
CSS. A URL to a good tutorial with demo/example will help.

I am trying to create a CSS for DocBook XML Document, but I m unable
to get a cross browser/platform compatibility. I want the documents to
look fairly similar on all platforms/browsers.

Here is my CSS -> http://www.xml-dev.com/blog/new.css
And here are 2 plaint text documents using that CSS:
http://tinyurl.com/yu3j8
http://tinyurl.com/2zwoh

More documents here -> http://www.xml-dev.com/blog/#88

I was told that I should always use "%" in defining font sizes. In
what scenario should the "em/ex/px" be used?

Thanks.
Saqib Ali
http://validate.sf.net
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sa***@stonebeat.org (Saqib Ali) wrote:
I was told that I should always use "%" in defining font sizes. In
what scenario should the "em/ex/px" be used?


em (and ex) are in theory just as good as % but in practice they
trigger a few more browser bugs, so % is preferred for font-size. Use
em for scalable derived styles (such as padding). ex is further
screwed on several platforms where it is just treated as 0.5em rather
than as the correct value for the font in question.

px is treated as screen pixels in all current browsers (despite the
CSS defining it quite differently). Use it just for items that are
naturally pixel sized (bitmap images and the like) and for styles that
are _directly_ related to such items. I must admit that I frequenly
break this rule and define borders in px sizes - despite the fact that
I know that for some users (poor vision or high res displays) my
borders will be impossible to see.

The physical units (in, pt, pica, cm, mm) are only useful when you
know the dimensions of the output medium. On the www this is virtually
never the case. Even print stylesheets may be applied to print outs on
different sized papers.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2

P: n/a
"Saqib Ali" <sa***@stonebeat.org> wrote in
comp.infosystems.www.authoring.stylesheets:
I want the documents to
look fairly similar on all platforms/browsers.


With respect, no, you don't. You want the document to look the way
that is most readable in each user's browser. Each user knows better
than you which font they can read best and how large or small they
prefer it.

User choice of fonts and font sizes probably has more to do with how
your document looks than user choice of browser, assuming you don't
use stoopid proprietary Microsoftisms.

Specify all font sizes in percents. Specify

body, p { font-size: 100% }

to get around a naughty bug in some releases of Internet Explorer.

Never specify fonts in pixels or inches or points. You could use
ems, but there's one situation (I forget which) where percent works
and ems don't -- again in one buggy version of MSIE.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.