Thomas: p+img -> andere Formatierung

Hallo an alle!
Ich hoffe, es kann mir von euch jemand helfen...

Ich möchte ein Bild stets einen border, padding und margin geben.
daher:

img.bild{  
border: 1px solid #8f0f40;  
padding: 3px;  
float: left;  
margin: 10px 10px 10p 0  
}

Wenn aber das Bild das erste Element einem <p> ist, soll der margin-top wegfallen, damit das Bild auf gleicher Höhe wie der Text (rechts daneben) beginnt.

Eigentlich dachte ich, dass dies so funktionieren sollte:

p+img.bild{  
margin-top: 0;  
}

Dem ist leider nicht so.

Was mache ich falsch bzw. wie funktioniert's?

Vielen Dank!

  1. Hi,

    Wenn aber das Bild das erste Element einem <p> ist, soll der margin-top wegfallen, damit das Bild auf gleicher Höhe wie der Text (rechts daneben) beginnt.

    Eigentlich dachte ich, dass dies so funktionieren sollte:

    p+img.bild{

    margin-top: 0;
    }

    
    >   
    > Dem ist leider nicht so.  
    >   
    > Was mache ich falsch  
      
    Du hast den falschen Selektor gewählt.  
    + ist der [adjacent sibling selector](http://www.w3.org/TR/CSS21/selector.html#adjacent-selectors) - "[E1 + E2] The selector matches if E1 and E2 share the same parent in the document tree and E1 immediately precedes E2"  
      
    
    > bzw. wie funktioniert's?  
      
    <http://www.w3.org/TR/CSS21/selector.html#first-child>  
      
    MfG ChrisB  
      
    
    -- 
    “Whoever best describes the problem is the person most likely to solve the problem.” [Dan Roam]