首页 > 其他 > 详细

居中百分比宽高的元素(司徒正美的例子)

时间:2014-12-22 21:05:05      阅读:269      评论:0      收藏:0      [点我收藏+]

以前工作碰到这个问题,但不知道具体怎么解决,看了正美的博客测试下,果然有效,

<!DOCTYPE html>
<html>
    <head>
        <title>百分比居中</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style>
            .center {
                      position: absolute;
                      left: 50%;
                      top: 50%;
                      /*Internet Explorer 10、Firefox、Opera 支持 transform 属性。*/
                        transform:translate(-50%,-50%);
                        -webkit-transform: translate(-50%,-50%);/* Safari and Chrome */
                        -moz-transform:translate(-50%,-50%);  /* Firefox */
                        -ms-transform:translate(-50%,-50%); /* IE 9 */
                        -o-transform:translate(-50%,-50%);/* Opera */
                      /*
                      甚至不要定义 
                      比如:Height 可以缺省!
                      */
                      width: 40%;
                      height: 50%;
                      /*height: auto;*/
                      background: red;
                    }
        </style>
    </head>
    <body>
        <div class="center">11111111111</div>
    </body>
</html>

可以参考

居中百分比宽高的元素(司徒正美的例子)

原文:http://www.cnblogs.com/heboliufengjie/p/4178830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!