垂直居中的几种方式
来源:互联网 发布:淘宝宝贝标题范文 编辑:程序博客网 时间:2024/06/01 10:03
垂直居中的几种方式
1.ie7+以上支持
绝对定位+各外边距为0+margin:auto
<!doctype html><html lang="en"> <head> <style> .div1{ background:blue; position:absolute; left:0; top:0; right:0; bottom:0; height:100px; width:100px; margin:auto; } </style> </head> <body> <div class = "div1">fsdaf</div> </body></html>
2. 支持ie6和其他浏览器(需要知道高度)
绝对定位+自身高度的一半
<style> div{ background:green; height:100px; width:120px; position:absolute; top:50%; left:50%; margin:-50px -60px;/*自身高度和宽度的一半*/ } </style> </head> <body> <div>fsdaf</div> </body>
3.自适应高度,支持ie6和其他浏览器
父级绝对定位+本身相对定位、inline-block、-50%;
</pre><pre name="code" class="html"> <style> .infoBox{ position:absolute; top:50%; width:100%; text-align:center; } .info{ display:inline-block; position:relative; top:-50%; right:0; border:1px solid; } </style> </head> <body> <div class = "infoBox"> <div class = "info"> fsdafdfsg fdgfd</div> </div> </body>
0 0
- 垂直居中的几种方式
- css垂直居中的几种方式
- 实现垂直居中的几种方式
- 实现垂直居中的几种方式
- 垂直居中实现的几种方式
- 垂直居中的几种方式
- 水平垂直居中的几种方式
- HTML几种设置水平居中和垂直居中的方式
- html里元素水平居中和垂直居中的几种方式
- 垂直居中的方式
- div 垂直 居中的几种 方法
- div垂直居中的几种办法
- div垂直居中的几种办法
- 垂直居中的几种实现方法
- 垂直居中的几种实现方法
- 实现垂直居中的几种方法
- 图片垂直居中的几种方法
- div垂直居中的几种方法
- Socket编程
- 将nodejs设置成开机自动启动
- 寻找数组中最大值
- 模糊查询mybatis
- (平方幂母函数)hdu 1398 Square Coins
- 垂直居中的几种方式
- 用Gradle 构建你的android程序
- android:SQLiteOpenHelper 与 greenDao 数据库操作
- C#实现三维数字地形漫游
- 字符串S2 是不是S1的反转(算法)
- 使用Maven管理Android项目
- iOS 键盘自适应(IQKeyboardManager)使用小结
- Linux下调试shell的几种方法
- 排序算法原理简述及C语言实现