Skip to content Skip to sidebar Skip to footer

How Do I Position A Div 'x' Pixels From The Center Of A Page?

I want to position a
a given number of pixels relative to the center of a page. How can this be done?

Solution 1:

You can use $(window).width() / 2 to get the horizontal center... like:

$('.myDiv').css({left: ($(window).width() / 2) - 50})

You'll get the div 50px left of the center


Post a Comment for "How Do I Position A Div 'x' Pixels From The Center Of A Page?"