Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save charisTheo/d21a8b05b30fc1271e6393304923b2b0 to your computer and use it in GitHub Desktop.

Select an option

Save charisTheo/d21a8b05b30fc1271e6393304923b2b0 to your computer and use it in GitHub Desktop.
var list = document.getElementById('list');
var listItems = Array.from(list.children);
for (var i = 0; i < listItems.length; i++) {
var listParentHeight = list.parentElement.offsetHeight; // No-No: calculate parent height in every loop
listItems[i].style.marginTop = Math.floor( listParentHeight / listItems.length - 10) + 'px';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment