/    Sign up×
Community /Pin to ProfileBookmark

Help with Clear:both required

Hi. I have stripped out most of the code from my page, and left in the essentials to demonstrate my problem.

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-gb” lang=”en-gb” >
<head>
<style type=”text/css” media=”screen”>
div#leftPanel {
float:left;
width:200px;
height:100px;
background:yellow;
}

div#mainPanel {
margin-left:250px;
background:red;
}

div#innerPanel {
background:green;
width:200px;
height:50px;
float:left;
}

</style>
</head>
<body>
<div id=”leftPanel”></div>
<div id=”mainPanel”>
<div id=”innerPanel”></div>
<div style=”clear:both”></div>
Here is some more text
</div>
</body>

</html>[/code]

The clear:both style in the inner div is pushing the subsequent text to below the height of the left panel. If i remove the doctype, the problem goes away, but obviously i don’t want be doing that.

I found it a bit difficult to explain in words, so i attach an image of how it should look and how it does look.

Can anyone help me out?

[upl-file uuid=defefbd9-69d1-42b3-a07e-a302d83c5ca6 size=6kB]demo.gif[/upl-file]

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 15.2009 — Remove <div style="clear:both"></div> and the float:left; from #innerPanel
Copy linkTweet thisAlerts:
@Typhoon101authorApr 16.2009 — I can't do that. As i said, i have stripped out most of the code and left only enough to demonstrate the problem. In reality, I need those there.

I nee help changing the CSS to fix the problem.
Copy linkTweet thisAlerts:
@CoyotelabApr 16.2009 — [code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css" media="screen">
div#container {
width: 98%;
margin: 0 auto;
}
div#leftPanel {
width:20%;
height:100px;
background:yellow;
float: left;
margin-right: 50px;
}
div#mainPanel {
background:red;
width: 75%;
float: left;
}
div#innerPanel {
background:green;
width:200px;
height:50px;
float:left;
}
div#text {
padding-top:50px;
}
</style>
</head>
<body>
<div id="container">
<div id="leftPanel"></div>
<div id="mainPanel">
<div id="innerPanel"></div>
<div id="text"> Here is some more text </div>
</div>
<div style="clear:both"></div>
</div>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@Typhoon101authorApr 16.2009 — Hmm. I thought stripping out the unnecessary code would make things simpler, but I appear to have just confused things a little. Here is a better example.

The output of this page is almost as I want. The only thing wrong is the main content appears below the left panel. As the text explains, removing the clear:both style pushes the text inbetween the two upper boxes.

I need a liquid layout. I cannot define heights as they will be different on each page.

[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
<head>
<style type="text/css" media="screen">
div#container {
width:900px;
margin:auto;
}

div#leftPanel {
float:left;
width:200px;
border:1px dashed red;
}

div#mainPanel {
margin-left:210px;
border:1px dashed green;
padding:10px;
}

div#topLeftPanel {
border:1px dashed orange;
width:250px;
padding:3px;
float:left;
}

div#topRightPanel {
border:1px dashed orange;
width:250px;
padding:3px;
float:right;
}

div#mainContent {
clear:both;
}


</style>
</head>
<body>
<div id="container">
<div id="leftPanel">
<p>This panel contains content of an undefined height.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
</ul>

</div>
<div id="mainPanel">
<div id="topLeftPanel">
This panel is a placeholder for text. The content is varies in size from page to page, so a height cannot be defined for it.
</div>
<div id="topRightPanel">
This panel is a placeholder for text. The content is varies in size from page to page, so a height cannot be defined for it.
</div>

<div id="mainContent">
<p>This is where the main content starts. If i do not add a clear:both style, the text appears in between the above two boxes. Adding the clear:all style moves the content to below the left hand panel</p>
<p>Because the height of the above two boxes is undefined, I cannot just add padding to the top of this containing div.</p>
</div>
</div>
</div>
</body>

</html>[/code]
Copy linkTweet thisAlerts:
@Typhoon101authorApr 20.2009 — Anyone able to help?
Copy linkTweet thisAlerts:
@FangApr 20.2009 —  div#topRightPanel {
border:1px dashed orange;
width:250px;
padding:3px;
[COLOR="Blue"]margin-left:150px;[/COLOR]
float:right;
}

<i> </i> div#mainContent {
<i> </i> }
×

Success!

Help @Typhoon101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...