Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

style="width:xxx"

Status
Not open for further replies.

ZiggyRingTail

Programmer
Jan 19, 2004
3
US
Hi all,

Is there a way to specifiy style="width:xx" so the unit of measure (xx in this case) is characters and not pixels?

Thanks
 
what characters would you be putting in there exactly?

from what you gave I would say no, but there may be more details. like scripting involvment maybe?

I can tell you what W3C says

___________________________________________________________________
onpnt2.gif

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
Well, sort of. An em is the average width of text characters (it used to be the width of an "m" character, hence the name). You might get three "i" characters, or just one "w" into a 2em-wide box. Of course this doesn't apply to monospaced fonts [tt]like this, where all characters have the same width.[/tt]

-- Chris Hunt
 
Hi all,

Thanks for the response. I'm not sure I understand what "em" is and how to use it. Is it intended to replace the "px" in style="width:150px"?

Thanks
 

>> Is it intended to replace the "px" in style="width:150px"?

It is. An "em" is exactly the width of 1 'm' character in whatever font you're using (thus the name 'em'). It stems from the printing trade, and made it over into the 20th century when everything got computerised. You also see references to em-dashes (like elongated hyphens) - these are dashes that are also the same width as a letter 'm'

Hope this clarifies things,

Dan
 
Thanks to everyone for your responses, that's exactly what I need!

Ziggy
 
Although it appears problem is solved, might I add one last thing? The available units of measurement in CSS are the following:

RELATIVE
em (height of elements font as explained above)
ex (height of the letter "x")
px (pixels relative to canvas resolution)

ABSOLUTE
in (inches)
cm (centimeters)
mm (millimeters)
pt (points, 1pt = 1/72 inch)
pc (picas, 1pc = 12pts)

Most literature recommends use of em over any other measurement and strongly dicourages use of absolute measurements. This is primarily for puposes of accesibility. I personally have found the 'em' unit to be perhaps the easiest to work with, although that's probably a matter of what one gets used to.

RKM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top