Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 21st, 2005, 12:57 AM
Florian Brucker
Guest
 
Posts: n/a
Default Border/Margin problem

I got a problem with code looking like that:

<div class="outer">
<div class="inner">
Sample text
</div>
</div>

The outer DIV has margin/padding=0, the inner DIV has a margin (all 4
sides). What happens is that the margin does not position the inner DIV
more to the inside of the outer one, but creates a margin between the
outer div and its parent. When a border is added to the outer DIV, it
renders as it (IMHO) should do.

A sample page showing both the problem and the border-workaround, can be
found at http://www.torfbold.com/problem.html

This happens over here on Linux with Mozilla 1.6 and Opera 7.51.

According to my understanding of the CSS Box model
(http://www.w3.org/TR/REC-CSS2/box.html), this is not the correct behaviour.

I would really appreciate it if some could clarify that mystery for me.

Thanks,
Florian
--
Minimum Requirement #3: You know where you want to go tomorrow
(WEB.DE help-wanted ad: Linux Guru)
[------------ http://www.torfbold.com - POV-Ray gallery ------------]
  #2  
Old July 21st, 2005, 12:57 AM
Lauri Raittila
Guest
 
Posts: n/a
Default Re: Border/Margin problem

In article <2sj6pcF1lmdvoU1@uni-berlin.de>, torf@torfbold.com says...[color=blue]
> I got a problem with code looking like that:
>
> <div class="outer">
> <div class="inner">
> Sample text
> </div>
> </div>
>
> The outer DIV has margin/padding=0, the inner DIV has a margin (all 4
> sides). What happens is that the margin does not position the inner DIV
> more to the inside of the outer one, but creates a margin between the
> outer div and its parent. When a border is added to the outer DIV, it
> renders as it (IMHO) should do.[/color]

Margins collapse. What you see is correct behaviour. See collapsing
margins in CSS spec. Google past posts here if you don't get it from
spec.

--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
  #3  
Old July 21st, 2005, 12:57 AM
Florian Brucker
Guest
 
Posts: n/a
Default Re: Border/Margin problem

> Margins collapse. What you see is correct behaviour. See collapsing[color=blue]
> margins in CSS spec. Google past posts here if you don't get it from
> spec.[/color]

Ooops. Seems I missed that part of the specs. Found it with your help.
Fixed it by using a padding on the outer div.

Thanks for your help!
Florian
--
In mathematics you don't understand things.
You just get used to them. (Johann von Neumann)
[------------ http://www.torfbold.com - POV-Ray gallery ------------]
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles