|
Posted by Lars Eighner on October 19, 2007, 6:52 am
Please log in for more thread options
In our last episode,
the lovely and talented Chris Mahoney
broadcast on comp.infosystems.www.authoring.html:
> Hi
> I'm not sure whether this is an HTML or CSS issue, but hopefully most
> of you in here would know at least some CSS :-)
> I have the following code:
><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
> www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
><html xmlns="http://www.w3.org/1999/xhtml">
><head>
> <meta http-equiv="Content-Language" content="en-nz" />
> <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8" />
> <title>Test</title>
></head>
><body>
> <p>
> <input type="text" style="width: 20em;" /><br />
> <textarea rows="2" cols="20" style="width: 20em;"></
> textarea><br />
> <select size="2" style="width: 20em;">
> <option>Test</option>
> </select>
> </p>
></body>
></html>
> I get different element widths in different browsers:
> IE 6 (XP): The Select element is smaller than the Input and Textarea
> elements.
> Firefox 2 (XP): All of the elements are different sizes.
> Netscape 9 (XP): Same as Firefox.
> Opera 9 (OS X): The elements are all different sizes, and are
> different from Firefox/NS.
> Safari 2 (OS X): The elements are all the same size.
> IE 5 (OS X): The elements are all the same size, although it somehow
> manages to pull a Euro symbol out of somewhere!
> I'm trying to make them all the same width, but have so far only
> managed to accomplish that in Safari and Mac IE. What am I doing
> wrong?
First, start with valid html. Your <p> and </p> are nonsense, and where is
the form element?
Once you have valid markup, most browsers will get the INPUT and SELECT*
elements the same size. The problem with the TEXTAREA element is that cols
is a required attribute, but its value is in "average character width" while
em in the style attribute is supposed to be the width of the widest
character in the font. The only kind of font in which those two will be
more or less equal is a monospaced font. When you have set font-family to
monospace (for each element) in valid markup, you will get almost equal
sized boxes in most browsers.*
*but the widget used for SELECT may throw things off a bit.
In short:
1) Write valid markup, even for examples.
2) Stop wanting that.
--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner> Countdown: 459 days to go.
What do you do when you're debranded?
|