实现水平垂直居中的五种方法
来源:互联网 发布:java中replaceall 编辑:程序博客网 时间:2024/05/17 05:59
水平垂直居中
<div class="wrapper"> <div class="inner"> </div></div>
1. 定位 + margin 方法
- 定位 + margin : auto;
.wrapper{ position:relative; width:300px; height:300px; border:1px solid black;}.inner{ position:absolute; top:0; left:0; bottom:0; right:0; width:100px; height:100px; background:orange; margin:auto;}
- 定位 + 负 margin
.wrapper{ position:relative; width:300px; height:300px; border:1px solid black;}.inner{ position:absolute; top:50%; left:50%; width:100px; height:100px; background:orange; margin-top:-50px; margin-left:-50px;}
- 定位 + transform
.wrapper{ position:relative; width:300px; height:300px; border:1px solid black;}.inner{ position:absolute; top:50%; left:50%; width:100px; height:100px; background:orange; transform:translate(-50%,-50%)}
2. 父元素 display:table-cell; 方法
.wrapper{ width:300px; height:300px; border:1px solid black; display:table-cell; vertical-align:middle;}.inner{ width:100px; height:100px; background:orange; margin: 0 auto;}
3. flex 弹性盒子 方法
.wrapper{ width:300px; height:300px; border:1px solid black; display:flex; justify-content:center; align-items:center;}.inner{ width:100px; height:100px; background:orange;}
4. inline-block + 伪元素 方法
.wrapper{ width:300px; height:300px; border:1px solid black; text-align:center;}.wrapper::after{ content:''; display:inline-block; height:100%; vertical-align:middle; }.inner{ width:100px; height:100px; background:orange; display:inline-block; vertical-align:middle;}
5. calc() + margin 方法
注意:运算符 - 或 + 两侧要加 空格
.wrapper{ width:300px; height:300px; border:1px solid black;}.inner{ width:100px; height:100px; background:orange; margin:calc((100% - 100px)/2);}
阅读全文
0 0
- 实现水平垂直居中的五种方法
- div垂直水平居中的五种方法
- 实现垂直水平居中的方法
- 用css实现垂直水平居中的几种方法
- 实现div水平、垂直居中的几种方法
- 【css】实现垂直水平居中的几种方法
- CSS实现水平垂直居中的几种方法
- css实现水平垂直居中的几种方法
- css实现垂直水平居中的5种方法
- 水平垂直居中的几种方法
- 水平垂直居中的几种方法
- css实现垂直居中和水平居中的方法
- 实现水平居中和垂直居中的方法
- 16种方法实现水平居中垂直居中
- 7种元素的水平居中和垂直居中方法
- div盒子水平居中垂直居中的几种方法
- 五种方法实现css垂直居中
- CSS实现垂直居中的五种方法
- L1-010. 比较大小
- Linux awk指令
- vbox虚拟机使用xshell
- vue 输入框 限定输入金额的范围并且用千分符显示,初始值有格式限制
- 写一个方法实现吧obj对象里的propertyName的属性值设置为value
- 实现水平垂直居中的五种方法
- 119. Pascal's Triangle II待续。。。
- 字符串循环移位
- L1-011. A-B
- 典型的字符串处理代码(algs4)
- FTP(vsftp)服务器的搭建配置以及访问控制
- 学以致用—股价月涨幅的计算
- 在Qtcreator下编译Nginx
- L1-012. 计算指数