Je dois centrer un div verticalement, avec seulement une marge au-dessus et au-dessous.Centrer un div verticalement
Donc je l'ai fait générer la marge avec JavaScript, comme ceci.
var xLength = ((document.getElementById("outerdiv").offsetHeight)+"px");
xLength = (xLength - 222); //222 is the Length of the to be centered div
xMargin = (xLength/2); //because of the 2 margins
xMargin = (xMargin());
document.getElementById(innerdiv).style.marginTop = xMargin;
document.getElementById(innerdiv).style.marginBottom = xMargin;
Aidez-nous, ne pouvez pas le mettre au travail, des idées?
Voici le CSS div interne et externe:
#outerdiv {
min-height:302px;
width:58px;
margin-left:640px;
z-index:2;
float:right;
margin-right:228px;
border: 1px solid black;
position:absolute;
}
#innerdiv {
height:222px;
width:58px;
position:absolute;
border: 1px solid green;
}
HTML:
<div id='outerdiv'>
<div id='innerdiv'>
</div>
</div>
Pouvez-vous faire un exemple de votre code actuel (html inluding) sur [jsFiddle] (http: // jsfid dle.net)? – sg3s
Il y a pas mal de problèmes avec ce code .. – thirtydot
Vous devriez publier tout le code, sinon nous ne pouvons pas vraiment vous aider. –