zoukankan      html  css  js  c++  java
  • css+div水平居中

    实现div内容水平居中

    实现方案一:margin:0 auto;

    div{
         height:100px;
         100px;
         background:red;
         margin:0 auto;
      }
    

      

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>div水平居中</title>
    	</head>
    	<body>
    		<div></div>
    	</body>
    </html>
    

      

    实现div水平居中方案二:position:absolute;绝对定位

    div{
        height:100px;
        width:100px;
        background:red;
        position:absolute;
       left:50%;
       right:50%;
       margin: auto;
    } 

    实现div水平垂直居中

    实现方案一:position:fixed;固定定位

    div{
                    height:100px;
                    width:100px;
                    background:red;
                    position:fixed;
                    left:0;
                    top:0;
                    bottom:0;
                    right:0;
                    margin:auto;
                }

    实现方案二:position:absolute;绝对定位

    div{
                    height:100px;
                    width:100px;
                    background:red;
                    position:absolute;
                    left:0;
                    top:0;
                    bottom:0;
                    right:0;
                    margin:auto;
                }

    实现方案二:css3+position;

    div{
                    height:100px;
                    width:100px;
                    background:red;
                    position:absolute;
                    left:50%;
                    top:50%;
                    transform:translate(-50%,-50%);
                }

    transform为css3的新增属性,因此需要加上前缀,兼容手机和其他的浏览器。如

    -ms-transform:translate(-50%,-50%); /* IE 9 */
    -moz-transform:translate(-50%,-50%); /* Firefox */
    -webkit-transform:translate(-50%,-50%);/* Safari and Chrome */
    -o-transform:translate(-50%,-50%); /* Opera */
  • 相关阅读:
    一个简单粗暴的爬虫
    Linux 目录结构
    python 部署 Restful web
    JVM 运行时数据区总结 栈 堆 堆大小配置总结
    成都法律援助申请流程
    JavaEE error整理(不断更新)
    ehcache.xml 属性大全
    SpringMVC 构建Restful风格 及问题处理
    Http Content-Type
    Redis 教程 Java工程师学习知识点
  • 原文地址:https://www.cnblogs.com/jaume/p/6978631.html
Copyright © 2011-2022 走看看