当前位置:网站首页>页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
2022-07-04 17:47:00 【回忆哆啦没有A梦】
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中
// 1
.wrapper {
position: relative;
.box {
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 100px;
margin: -50px 0 0 -50px;
}
}
// 2 我最常用的
.wrapper {
position: relative;
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
// 伪类+vertical-align: middle;
.box{
vertical-align: middle;
display: inline-block;
}
.wrapper::after{
content: '';
height: 100%;
width: 0;
vertical-align: middle;
display: inline-block;
}
// 3
.wrapper {
.box {
display: flex;
justify-content:center;
align-items: center;
height: 100px;
}
// 4
.wrapper {
display: table;
.box {
display: table-cell;
vertical-align: middle;
}
}
边栏推荐
- 启牛开的证券账户安全吗?
- Scala basic tutorial -- 19 -- actor
- Other InterSystems%net tools
- 自由小兵儿
- What if the self incrementing ID of online MySQL is exhausted?
- Build your own website (15)
- The 15th youth informatics competition in Shushan District in 2019
- Unity editor extends C to traverse all pictures in folders and subdirectories
- 2022年字节跳动日常实习面经(抖音)
- 物联网应用技术的就业前景和现状
猜你喜欢

ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development

建立自己的网站(15)

自由小兵儿

Angry bird design based on unity

Scala基础教程--17--集合

Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join

How is the entered query SQL statement executed?

Scala基础教程--20--Akka

My colleagues quietly told me that flying Book notification can still play like this

Build your own website (15)
随机推荐
【uniapp】uniapp开发app在线预览pdf文件
《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
Go microservice (II) - detailed introduction to protobuf
6.26cf simulation race e: solution to the problem of price maximization
建立自己的网站(15)
Wireshark网络抓包
技术分享 | 接口测试价值与体系
IBM WebSphere MQ retrieving messages
小发猫物联网平台搭建与应用模型
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
Caché WebSocket
Li Kou brush question diary /day2/2022.6.24
node_exporter部署
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
Rookie post station management system based on C language
IBM WebSphere MQ检索邮件
使用FTP
[go ~ 0 to 1] read, write and create files on the sixth day
Unity editor extends C to traverse all pictures in folders and subdirectories
php伪原创api对接方法