Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想<div>相对于页面中心定位给定数量的像素。如何才能做到这一点?
<div>
您可以使用$(window).width() / 2来获得水平中心...例如:
$(window).width() / 2
$('.myDiv').css({left: ($(window).width() / 2) - 50})
你会得到div 50px中心的左边
div
50px