martin.richter: Margin will nicht so wie ich will

Hallo,

warum wird der margin-top-Wert des 2. DIVs (rot) nicht anerkannt?

Er macht keinen Abstand zwischen dem roten und grünen (rot in grün bessergesagt) sondern setzt den Abstand anscheinend oberhalb des grünen DIVs.

Danke,
Martin

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
<html>  
<body>  
  
<div style="position:relative;width:790px;height:150px;margin:0px auto;background:green">  
  
<div style="position:relative;margin-left:3px;margin-top:50px;width:600px;height:22px;background:red"></div>  
</div>  
  
</body>  
</html>
  1. warum wird der margin-top-Wert des 2. DIVs (rot) nicht anerkannt?
    Er macht keinen Abstand zwischen dem roten und grünen (rot in grün bessergesagt) sondern setzt den Abstand anscheinend oberhalb des grünen DIVs.

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

    <html>
    <body>
    <div style="position:relative;width:790px;height:150px;margin:0px auto;background:green">
    <div style="position:relative;margin-left:3px;margin-top:50px;width:600px;height:22px;background:red"></div>
    </div>
    </body>
    </html>

      
    Das äussere Element hat border:0px; padding:0 weshalb vertikale margins des inneren Elements mit den margins des äusseren kollabieren.  
      
    Eventuell willst du eher mit dem padding des äusseren Elements arbeiten, als mit dem margin des inneren Elements.  
      
    mfg Beat
    
    -- 
    Woran ich arbeite:  
    [link:http://www.elcappuccino.ch/cgi/tok.pl?extern=1-pub-com3306-1@title=X-  
    
    ><o(((°>           ><o(((°>  
    
       <°)))o><                     ><o(((°>o  
    
    
  2. Hi,

    Er macht keinen Abstand zwischen dem roten und grünen (rot in grün bessergesagt) sondern setzt den Abstand anscheinend oberhalb des grünen DIVs.

    Hat "er" brav gemacht -
    Css 2.1, 8.3.1 Collapsing margins:
    "The top margin of an in-flow block-level element is adjoining to its first in-flow block-level child's top margin if the element has no top border, no top padding, and the child has no clearance."

    MfG ChrisB

    --
    „This is the author's opinion, not necessarily that of Starbucks.“