Html, div, style et margin

Résolu
santiago69 Messages postés 485 Statut Membre -  
santiago69 Messages postés 485 Statut Membre -
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 257 Statut Membre 41
 
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