Forum Moderators: open

Message Too Old, No Replies

Doctype URI causes wrong interpretation of CSS

         

Jay7

3:42 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



I am trying to change the width of next form items in my HTML:

<input type="text" name="X" style="width:100px">

<select name="Y" style="width:100px">
<option value="A">A</option>
</select>

<textarea name="W" cols="15" rows="3" style="width:100px"></textarea>

Everything works well when there is no DTD specified, or with HTML4.01 Transitional:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

However, if I add the URI to the doctype, both IE and Firefox (on Win XP) add 4px to the text box and textarea (not to the select box):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Am I doing something incorrectly?

drhowarddrfine

3:50 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding a doctype, or changing it, will not cause CSS to be interpreted incorrectly. Possibly what is happening is a little margin is being added that wasn't there before but I really don't recall since I've never used transitional or 'none' before.

In your CSS, add * {margin:0;padding:0;} and see if the problem goes away.

Receptional Andy

3:52 pm on Feb 20, 2006 (gmt 0)



This has come up before:

adding a doctype makes my navigation section disappear [webmasterworld.com]
and
Doctype for mongrel site [webmasterworld.com]

See also Quirks Mode vs. Standards Mode - overview [webmasterworld.com]

[edited by: Receptional_Andy at 3:53 pm (utc) on Feb. 20, 2006]

Jay7

3:53 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



Thanks drhowarddrfine, but margin is set to zero. Adding the DTD URI really changes the width of the form items.

Here is the full code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;">
<title>Test</title>

<style type="text/css">

body, input, select, textarea {
font-family: Arial;
font-size: 11px;
}
.form1 {
width: 150px;
margin: 0;
padding: 0;
}

</style>

</head>
<body>

<input type="text" name="X" class="form1"><br>

<select name="Y" class="form1">
<option value="A">A</option>
</select><br>

<textarea name="W" cols="15" rows="3" class="form1"></textarea><br>

</body>
</html>

kaled

6:13 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note sure about Firefox, however, if the url is omitted for a 4.01 HTML Trans doctype, IE will revert to quirks mode. This is a deliberate design feature documented by MS.

Kaled.

encyclo

6:17 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All major browsers now support doctype-switching, and the URL-less HTML 4.01 Transitional means that the page is in "quirks mode" rather than the correct "standards-compliance mode" which should be favored for new pages.

If I understand it correctly, you are getting 4px added to the width? If so, this is normal as in standards mode the borders are outside the box, not inside. You simply need to adjust your width in consequence so that the total width equals 100px.

Wlauzon

9:26 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IBM has a good article on DOCTYPES here:

[www-128.ibm.com...]

drhowarddrfine

2:36 am on Feb 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE will revert to quirks mode. This is a deliberate design feature documented by MS.
Makes me laugh.

Jay7

9:14 am on Feb 21, 2006 (gmt 0)

10+ Year Member



If I understand it correctly, you are getting 4px added to the width?

Yes, but only to the text field and text area. Not to the select box. Weird. :(