当前位置:网站首页>The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
2022-07-04 19:25:00 【Memories do not have a dream】
Page elements centered vertically and horizontally 、 Vertical horizontal centering of known or unknown width
// 1
.wrapper {
position: relative;
.box {
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 100px;
margin: -50px 0 0 -50px;
}
}
// 2 What I use most
.wrapper {
position: relative;
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
// pseudo-classes +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;
}
}
边栏推荐
- 大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
- 工厂从自动化到数字孪生,图扑能干什么?
- “只跑一趟”,小区装维任务主动推荐探索
- Summary and sorting of 8 pits of redis distributed lock
- Build your own website (15)
- [go ~ 0 to 1] read, write and create files on the sixth day
- 添加命名空间声明
- 神经网络物联网是什么意思通俗的解释
- Detailed explanation of issues related to SSL certificate renewal
- php伪原创api对接方法
猜你喜欢
随机推荐
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
正则替换【JS,正则表达式】
To sort out messy header files, I use include what you use
2021 Hefei informatics competition primary school group
技术分享 | 接口测试价值与体系
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Is the securities account opened by qiniu safe?
One question per day (2022-07-02) - Minimum refueling times
Go microservice (II) - detailed introduction to protobuf
Angry bird design based on unity
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
2019年蜀山区第十五届青少年信息学竞赛
Basic tutorial of scala -- 16 -- generics
2022 ByteDance daily practice experience (Tiktok)
Wireshark网络抓包
测试工程师如何“攻城”(下)
资料下载 丨首届腾讯技术开放日课程精华!
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Detailed explanation of issues related to SSL certificate renewal