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. python使用dbutils的PooledDB连接池,操作数据库

    1.使用dbutils的PooledDB连接池,操作数据库. 这样就不需要每次执行sql后都关闭数据库连接,频繁的创建连接,消耗时间 2.如果是使用一个连接一直不关闭,多线程下,插入超长字符串到数据库 ...

  2. linux 使用supervisor来管理进程

    现在假设一个脚本是,hello.py,内容是 fo = open('xx.txt','w') while 1: fo.write('hello world') print('hi') time.sle ...

  3. linux系统调用函数---12

    Linux应用编程学习笔记                                 周学伟 一.系统调用文件编程   1.文件打开函数 /*************************** ...

  4. MyBatis踩坑记录

    在线文档: 动态SQL  http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html 1. Error setting null for paramete ...

  5. JQuery Mobile 简单入门引导

    看了慕课网的jqm视频(http://www.imooc.com/learn/207),觉的不错,简单截几个图,做一下备忘:

  6. phonegap入门–2 Android phonegap工程建立

    一.环境要求: 需要安装Android ADT 二.支持Android相关设备列表: a)Android 2.1 (Deprecated May 2013) b)Android 2.2 c)Andro ...

  7. web.xml 整合 SpringMVC

    啦啦啦 <context-param> <param-name>defaultHtmlEscape</param-name> <param-value> ...

  8. Axis2发布服务,支持Tomcat和Weblogic的SSHWeb项目部署

    先说下遇到的问题,在SSHWeb项目中使用JDK自带的jar发布WebService(Endpoint.publish),在tomcat下可以正常发布,但是在Weblogic报奇葩错误,如Struts ...

  9. iptables相关操作以及简单理解端口和服务之间关系

    一般CentOS7默认安装的是firewall不是iptables 1.查看firewall状态 firewall-cmd --state 关闭后显示not running,开启后显示running ...

  10. CM和CDH的安装-进阶完成

    安装Cloudera Manager Server 和Agent 1.在cdh1解压cloudera-manager-el6-cm5.9.0_x86_64.tar.gz(cdh1节点)tar -zcv ...