方法一:
对一个div进行以下设置即可实现居中。
CSS Code复制内容到剪贴板- #a{
- position: fixed;
- top: 0px;
- left: 0px;
- rightright: 0px;
- bottombottom: 0px;
- margin: auto;
- }
-
document 123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
123
-
- sdvcdvf
效果:
方法二:
使用js操作div的属性为下面这样即可实现居中。
Javascript Code复制内容到剪贴板- #a{
- width: 200px;
- height: 200px;
- background-color: aquamarine;
- position: fixed;
- }
效果:
以上这篇设置一个DIV块固定在屏幕中央的两种方法(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。
原文地址:http://www.cnblogs.com/gaotenglong/archive/2016/07/24/5701434.html




