Html, div, style et margin

Résolu/Fermé
santiago69 Messages postés 477 Date d'inscription mercredi 7 mars 2001 Statut Membre Dernière intervention 12 septembre 2016 - 14 oct. 2008 à 17:40
santiago69 Messages postés 477 Date d'inscription mercredi 7 mars 2001 Statut Membre Dernière intervention 12 septembre 2016 - 20 oct. 2008 à 18:48
Salut a tous,

Je n'arrive pas a comprendre le comportement de la propriete margin.
Soit la page suivante :
<html><body>
<div style="width:200px ; height:200px ; background:red">
    <div style="margin-left:40px ; margin-top:40px ; width:100px ; height:100px ; background:green">
    </div>
</div>
</body></html>

J'ai fait 3 test : test1.htm test2.htm test3.htm
margin-left est bien calculee entre le bord du premier div et le bord du deuxieme div
pourtant margin-top, est applique entre le bord de la page et le bord du premier div alors qu'il est defini dans le 2e div.

Est ce que quelqu'un peut m'expliquer ?

Cordialement
Santiago


A voir également:

4 réponses

Stef60 Messages postés 251 Date d'inscription jeudi 31 mai 2007 Statut Membre Dernière intervention 22 avril 2009 41
14 oct. 2008 à 18:58
Bonjour,
tu cherches à faire ca:
<html>
<body>

<div style="width:200px ; height:200px ; background:red; position:absolute;">
<div style="margin-left:40px ; width:100px ; margin-top:40px ;height:100px ; background:green">
</div>
</div>

</body>
</html>


ou ca (plus jolie à mon gout)
<html>
<body style="margin:0 ; paddin:0 ;">

<div style="width:200px ; height:200px ; background:red; position:absolute;">
<div style="margin-left:40px ; width:100px ; margin-top:40px ;height:100px ; background:green">
</div>
</div>

</body>
</html>
9