How do I position a div 'x' pixels from the center of a page?

守給你的承諾、 提交于 2019-12-12 00:55:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!