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

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

伊谢尔伦
伊谢尔伦

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

Antworte allen(6)
洪涛

用js获取窗口大小和元素位置,然后根据拿到的值去设置内容位置,纯css也可以,但是感觉灵活度不够高

伊谢尔伦

推荐一下自己的博客:http://blog.csdn.net/zp1996323/article/details/50936259,实现的效果都是垂直居中水平居中

小葫芦

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实现方法(width和height事先知道):需要居中的层采用绝对定位,结合left、top、margin-left和margin-top实现居中。
2、js实现,这个就不多说了。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!