css3 - 怎样让网页里的内容随着浏览器窗口改变而自动居中
伊谢尔伦
伊谢尔伦 2017-04-17 11:33:55
0
6
550

就是让网页里的内容随着浏览器窗口改变时跟着自动居中呢……怎样实现?有好点的常用的思路吗

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(6)
洪涛

Use js to get the window size and element position, and then set the content position according to the obtained values. Pure css can also be used, but it feels not flexible enough

伊谢尔伦

Recommend your own blog: http://blog.csdn.net/zp1996323/article/details/50936259, the effect achieved is vertical centering and horizontal centering

小葫芦

margin-right:auto;
margin-left:auto

黄舟

position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
width:XXpx;
height:XXpx;

黄舟
position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
width:XXpx;
height:XXpx;

这个方法不兼容IE6/7,移动端考虑可以使用。
大家讲道理

1. CSS implementation method (width and height are known in advance): The layer that needs to be centered uses absolute positioning, and combines left, top, margin-left and margin-top to achieve centering.
2. js implementation, I won’t say much about this.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!