问题
I want to position a <div>
a given number of pixels relative to the center of a page. How can this be done?
回答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
来源:https://stackoverflow.com/questions/11905699/how-do-i-position-a-div-x-pixels-from-the-center-of-a-page