css3 居中定位方法

来源:互联网 发布:蒙古语翻译软件 编辑:程序博客网 时间:2024/06/03 12:56

html中实现div居中定位的方法:CSS部分代码如下:

css代码如下:方法(1):.test {width:100px;height:100px;background:#000;position:absolute;left:0;top:0;margin-left:-50px;margin-top:-50px;}方法(2):.test {width:120px;height:120px;position:absolute;margin:auto;left:0;right:0;top:0;bottom:0;}方法(3):.test {width:100px;height:100px;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);-webkit-transform:translate(-50%,-50%);-moz-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);-o-transform:translate(-50%,-50%);}


原创粉丝点击