mardi 22 juin 2021

Why does Client Height value doesn't apply to other elements? [duplicate]

I want my sidebar to have spacing from top equal to header's height. When I use clientHeightin js, although it returns the right value when I print it via alert(), it doesn't apply to other elements as marginTop or top value. (Position was included while using top).

HTML

<body onload="sidenav_height()">
 ...
</body>

JS

function sidenav_height(){
  var height = document.getElementById("header").clientHeight;
  document.getElementById("sidenav").style.marginTop = height;
}



Aucun commentaire:

Enregistrer un commentaire