让设置position为fixed的div剧中的方式

让设置position为fixed的div剧中的方式:

1,交给浏览器自适应

左右剧中:
position:fixed;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
或者:
position:fixed;
left:0;
right:0;
margin:auto;

上下居中:
position:fixed;
margin:auto;
top:0;
bottom:0;aa 

例子:

position:fixed;
top:50px;
z-index:88;
width:1100px;
height:64px;
border:2px solid red;
left:0;
right:0;
margin:auto;
View Code

2,浮动50%再左移动自身的一半

position: fixed;
z-index:1;
top: 50%;
left: 50%;
margin: -141px 0 0 -201px;
width: 400px;
height:280px;
设置 position: fixed; 
设置 left:50% 和 top:50%;
设置 margin: -(DIV的offsetWidth/2) 0 0 -(DIV的offsetHeight/2

 

posted @ 2019-07-22 00:20  假程序猿  阅读(1078)  评论(0)    收藏  举报