1、水平居中
.footer {
height: 10%;
text-align: center;
position: relative;
left: 50%;
transform: translate(-50%, -50%); /*水平居中*/
top: 30px;
} 2、垂直居中:
.footer {
height: 10%;
text-align: center;
position: fixed;
top: 50%;
transform: translate(-50%, -50%); /*水平居中*/
left: 30px;
}
3、万能居中法:

#name{
position:fixed;
left:50%;
top:50%;
transform:translate(-50%,-50%);
z-index:1000;
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

通常情况下,我们通过操作margin来控制元素居中,代码如下:

1 #name{
2 maigin:0px auto;
3 }

但当我们把position设置为fixed时,例如:

1 #id{
2 position:fixed;
3 margin:0px auto;
4 }

以上代码中的margin:0px auto;会出现失效问题,盒子并未居中。这是因为fixed会导致盒子脱离正常文档流。
解决方法非常简单,只要应用如下代码即可:

1 #name{
2 position:fixed;
3 margin:0px auto;
4 right:0px;
5 left:0px;
6 }

若希望上下也可以居中,可采用如下代码:

1 #name{
2 position:fixed;
3 margin:auto;
4 left:0;
5 right:0;
6 top:0;
7 bottom:0;
8 }

万能居中法(未知大小呦):

1 #name{
2 position:fixed;
3 left:50%;
4 top:50%;
5 transform:translate(-50%,-50%);
6 z-index:1000;
7 }

position fixed 居中的更多相关文章

  1. css3 position fixed居中的问题

    通常,我们要让某元素居中,会这样做: #element{ margin:0 auto; } 假设还想让此元素位置固定呢?一般我们会加入position:fixed,例如以下: #element{ po ...

  2. position:fixed 居中问题

    设置Css属性position:fixed后如何使这个盒子居中呢?其实也很简单: 就是需要设置给这个div盒子设置属性: left:0; right:0; margin:0 auto; ******* ...

  3. 关于position:fixed;的居中问题

    通常情况下,我们通过操作margin来控制元素居中,代码如下: #name{ maigin:0px auto; } 但当我们把position设置为fixed时,例如: #id{ position:f ...

  4. css中position:fixed实现div居中

    上下左右 居中 代码如下 复制代码 div{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; h ...

  5. position:fixed;如何居中

    div{ position:fixed; margin:auto; left:; right:; top:; bottom:; width:100px; height:100px; } 如果只需要左右 ...

  6. position:fixed div如何居中

    div{position:fixed;margin:auto;left:0; right:0; top:0; bottom:0;width:200px; height:150px;}

  7. day2-设置position:fixed/absolute无法使用margin:auto调整居中

    问题描述:父元素给定宽度,子元素给定宽度,设置子元素position为absolute/fixed后,无法使用margin:auto使子元素在父元素中水平居中 html代码如下: <div cl ...

  8. 使用属性position:fixed的时候如何才能让div居中

    css: .aa{ position: fixed; top: 200px; left: 0px; right: 0px; width: 200px; height: 200px; margin-le ...

  9. 元素设置position:fixed属性后IE下宽度无法100%延伸

    元素设置position:fixed属性后IE下宽度无法100%延伸 IE bug 出现条件: 1.div1设置position:fixed属性,并且想要width:100%的效果. 2.div2(下 ...

随机推荐

  1. ul li列表元素浮动导致border没有底边解决办法

    如图,当ul li,li元素浮动,并且ul元素也overflow:hidden清除浮动的时候,给li元素加了border,但是不显示底边,这时候要看是不是没有给li元素加高,因为加了border之后默 ...

  2. css实现图片横向排列滚动

    .imageList{ overflow-x: auto; overflow-y: hidden; height:180px; white-space: nowrap; img{ width:auto ...

  3. js粘贴事件paste简单解析及遇到的坑

    在用户执行粘贴操作的时候,js能够获得剪切板的内容,本文讨论一下这个问题. 目前只有Chrome支持获取剪切板中的图片数据.还好需要这个功能的产品目前只支持Chrome和Safari,一些Chrome ...

  4. MyEclipse使用笔记

    简单记录下个人常用的一些MyEclipse设置 VS颜色方案 Window-->Preference-->Java->Editor-->Syntax Coloring Clas ...

  5. centos 中文乱码解决途径

    在使用CentOS系统时,安装的时候可能你会遇到英文的CentOS系统,在这中情况下安装CentOS系统时是默认安装(即英文).安装完毕后,出现的各种中文乱码.那么,我们如何解决这种问题呢. 一.Ce ...

  6. python怎么写可读性好的面向过程的长篇代码?

    最近接受老代码,mmp的,说是重新运行运行起来,那还不如重写呢,因为有很多毛病,不能直接运行,pep8就不用妄想奢望了,还有包括语法错误问题和内存严重泄露的问题(运行几分钟后python.exe进程达 ...

  7. PHP 免费获取手机号码归属地

    一.淘宝网API API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443 参数: tel:手机号码 返回 ...

  8. grid网格的流动grid-auto-flow属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. tomcat运行模式APR安装

    centos6.2下,Tomcat运行模式apr安装过程,如下: 一.安装apr [root@vmT227-m5 /]# cd /usr/local/ [root@vmT227-m5 local]# ...

  10. Incorrect column count: expected 1, actual 5,JdbcTemplate queryForList 出错

    spring JdbcTemplate  queryForList 出错 Incorrect column count: expected 1, actual 5 >>>>&g ...