Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
margin-top of div doubles if adjacent parent div has no border
Old 09-03-2010, 11:26 AM margin-top of div doubles if adjacent parent div has no border
c--
Junior Talker

Posts: 2
Trades: 0
Hi,

I use several (in my example 2) div boxes with absolute width (200) on the left and a box with variable width (remaining space) on the right.
The boxes on the left are included in a container (divleft), the box on the right is included in divright.

In my example, the right container has a red border.
If I remove this border (i.e. change 1px to 0px), then "BOX1" has double its distance to the top of the page - which is 20 pixels (while "BOX RIGHT" is still 10 pixels from the top). If I change the margin of the class "box" from 10px to 5 px, then only "BOX RIGHT" is 5 pixels from the top, while "BOX1" is 10 pixels from the top.

Can somebody please explain this behavior to me?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<style type="text/css">

* { margin:0px; padding:0px; }

#divleft { float:left; width:200px; border:0px solid red; } /* left container */
#divright { margin-left:200px; border:1px solid red; } /* right container */

.box { border-style:solid; border-color:gray; border-width:1px; margin:10px; padding:5px; } /* This margin is not always 10px */
.boxtitle { background-color:gray; color:white; font-weight:bold; margin:0px; padding:5px; }

</style>
</head>
<body>

<div id="divleft"> <!-- left container -->

<div class="box"> <!-- BOX1 -->
<p class="boxtitle">BOX1</p>

---<br>

</div>



<div class="box"> <!-- BOX2 -->
<p class="boxtitle">BOX2</p>

---<br>

</div>

</div>

<div id="divright"> <!-- right container -->

<div class="box"> <!-- BOX RIGHT -->
<p class="boxtitle">BOX RIGHT</p>


TESTMAIN!
<br>

</div>


</div>

</body>
</html>

Last edited by c--; 09-03-2010 at 12:44 PM..
c-- is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-03-2010, 12:06 PM Re: margin-top of div doubles if adjacent parent div has no border
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,376
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And the rest of the CSS style rules can be seen where?

Or better still a link to the page.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-03-2010, 12:43 PM Re: margin-top of div doubles if adjacent parent div has no border
c--
Junior Talker

Posts: 2
Trades: 0
There is no rest, that's it!

Forget about "boxleft" and "boxright"...
c-- is offline
Reply With Quote
View Public Profile
 
Old 09-03-2010, 05:11 PM Re: margin-top of div doubles if adjacent parent div has no border
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Margin collapse, which is NOT a bug. Add 1px top padding to #divright.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to margin-top of div doubles if adjacent parent div has no border
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.98358 seconds with 12 queries