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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd CSS behaviour in IE

Status
Not open for further replies.
Dec 8, 2003
17,047
GB
I've run into a nasty problem with CSS and IE 6 (and possibly other versions), and was wondering if anyone could tell me why I'm seeing what I'm seeing.

Run the code below:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta http-equiv="content-language" content="en" />
	<title>IE CSS Bug?</title>

	<style type="text/css">
		#line1 {
			float: left;
		}

		#line2 {
			margin-top: 50px;
			clear: left;
			background-color: #FF0000;
		}
	</style>
</head>
<body>
	<div>
		<span id="line1">Line 1</span>
		<div id="line2">Line 2</div>
	</div>
</body>
</html>

Now, modify the code, and remove the background colour - and watch how line 2 is pushed down the page.

Has anyone else seen this behaviour before, or have any idea why IE is does this?

Incidentally, IE also exhibits the same behaviour with an HTML 4.01 Loose DOCTYPE and no DOCTYPE.

Thanks!
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
I'm a little vague on CLEAR: but if you remove it then line 2 snaps back where it's supposed to be.
 
Seems to be somethign to do with the clear:left

if you take it out

Code:
    <style type="text/css">
        #line1 {
            float: left;
	}

        #line2 {
            margin-top: 50px;
		background-color:#ff0000;

        }
    </style>

Then you get the same result, but no shifting.

Foamcow Heavy Industries - Web design and ranting
Toccoa Games - Day of Defeat gaming community
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
"I'm making time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top