CSS多种方式实现元素水平垂直居中
2024-09-08 14:23:18
html结构:
<div class="center">确定宽高水平垂直居中</div>
<div class="center2">不确定宽高水平垂直居中</div>
<div class="center3">确定宽高水平垂直居中2</div>
<div class="center4"><span>flex水平垂直居中</span></div>
<div class="center5"><span>table-cell水平垂直居中</span></div>
css样式:
.center{
position: absolute;
background: blue;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
left: 50%;
top: 50%;
margin-left: -100px;
margin-top: -100px;
}
.center2{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -150%);
background: red;
}
.center3{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
width: 100px;
height: 100px;
background: green;
}
.center4{
background: orange;
display: flex;
justify-content: center;
align-items: center;
height: 100px;
}
.center5{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 300px;
width: 400px;
background: red;
}
PS:仅作记录.
最新文章
- php入门一ubuntu16.04中php环境配置及一个网页
- Linux进程间通信(五):信号量 semget()、semop()、semctl()
- iOS-----About Asset Catalog
- WinForm 窗体应用程序 (初步)之二
- 如何修改VPN连接的MTU,解决频繁断线和页面打不开的问题
- 【M35】让自己习惯于标准C++语言
- 【Knockout】五、创建自定义绑定
- 链表与Hash检索实测
- 正则表达式:网页爬虫:从TXT中获取邮箱地址(获取的练习,缺点:一行只能匹配一个)
- javascript类型转换、运算符、语句
- hibernate_@GeneratedValue
- Flutter环境搭建
- MySQL - exists与in的用法
- loading加载的代码
- ns3的输入输出奥秘(二) 命令行参数
- 下面属于javascript对象的有:( )
- Hbase 之 HBase 的整体架构
- PPTP
- mongodb查看数据库和表的信息
- 【DB2】判断连续时间,如果间断则新增一条记录