如何从页面中心定位div'x'像素? [英] How do I position a div 'x' pixels from the center of a page?
本文介绍了如何从页面中心定位div'x'像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将相对于页面中心的给定数量的像素定位为< div>
。如何做到这一点?
解决方案
您可以使用 $(window).width()/ 2
来获得水平居中......像:
$('。myDiv')。css ({left:($(window).width()/ 2) - 50})
您将获得中心左边的 div
50px
I want to position a <div>
a given number of pixels relative to the center of a page. How can this be done?
解决方案
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
这篇关于如何从页面中心定位div'x'像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文