弹层高度宽度不确定,始终上下左右居中(css方法)
2018-01-04 11:22
537 查看
1.translate定位 这是css3 transform的属性 ,可以将宽高度设为百分比 IE browser<IE9不支持 在移动端使用较好
html代码:
<div class="translateCenter">我是translate居中定位</div>
css代码:
<style>
*{margin:0;padding:0}
.translateCenter{ width: 40%; height: 20%; position: absolute; left:50%; top:50%; transform:translate(-50%,-50%); background: #2d2d2d;}
</style>
2.margin居中定位 不需要确定div的宽高度 让top,bottom,left,right都为0 再加个margin:auto 神来之笔 IE browser< IE 8不支持
html代码:
css代码:
html代码:
<div class="translateCenter">我是translate居中定位</div>
css代码:
<style>
*{margin:0;padding:0}
.translateCenter{ width: 40%; height: 20%; position: absolute; left:50%; top:50%; transform:translate(-50%,-50%); background: #2d2d2d;}
</style>
2.margin居中定位 不需要确定div的宽高度 让top,bottom,left,right都为0 再加个margin:auto 神来之笔 IE browser< IE 8不支持
html代码:
<body> <div class="marginCenter">我是margin居中定位</div> </body>
css代码:
<style> *{margin:0;padding:0} .marginCenter{ width:200px; height: 200px; position: absolute;left:0; top:0; right:0; bottom: 0; margin: auto; background: #f2056e;} </style>
相关文章推荐
- 弹层高度不固定,始终上下居中(js方法)
- css:子元素div 上下左右居中方法总结
- CSS处理文本上下、左右居中的方法,以及最右边列自动适应
- css实现高度或者宽度不固定的div元素垂直左右居中
- 图片自适应父元素大小,并左右上下居中的css方法
- 图片自适应父元素大小,并左右上下居中的css方法
- css3 上下左右居中子元素的方法
- 不固定宽度和高度的情况下CSS调整div居中的方法总结
- css:子元素div 上下左右居中方法总结
- 在不确定自身高度的情况下,用 CSS 实现元素垂直居中的3种方法
- 实现任意图片(高度不确定)垂直居中的三种方法
- 用纯CSS实现容器内图片上下左右居中
- 图片上下左右居中css
- css在高度为百分比时候的文字垂直居中方法
- css实现内容上下左右居中的效果
- css实现div中的图片自动上下左右居中
- CSS控制页面最大最小宽度和高度可兼容IE6版本的实现方法
- CSS 上下左右居中笔记
- css---flex布局中,如何响应式 得水平垂直居中?flex子元素左右 上下居中
- css 垂直居中,指定文本宽度换行,指定高度出滚动条