Revision: 53525
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 25, 2011 21:44 by Neven
Initial Code
function CenterInsideDiv(divContainer,elementToCenter) { var divContainerHeight = divContainer.height(); var elementToCenterHeight = elementToCenter.outerHeight(); var elementNewTop = divContainerHeight / 2 - elementToCenterHeight / 2; elementToCenter.css({ top: elementNewTop, left: 0 }); } // call function like this CenterInsideDiv($("#elementToCenterId").parent(), $("#elementToCenterId"));
Initial URL
Initial Description
Position of the element to center needs to be relative to the container.
Initial Title
Center element inside of a div container
Initial Tags
center
Initial Language
JavaScript