当前位置:网站首页>页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
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;
}
}
边栏推荐
- 李迟2022年6月工作生活总结
- 性能优化之关键渲染路径
- Li Kou brush question diary /day3/2022.6.25
- Basic tutorial of scala -- 16 -- generics
- Send and receive IBM WebSphere MQ messages
- 完善的js事件委托
- Detailed explanation of issues related to SSL certificate renewal
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
- 其他InterSystems %Net工具
- Is the securities account opened by qiniu safe?
猜你喜欢
[release] a tool for testing WebService and database connection - dbtest v1.0
OpenCV的二值化处理函数threshold()详解
Li Kou brush question diary /day2/2022.6.24
Bi skills - permission axis
每日一题(2022-07-02)——最低加油次数
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Scala基础教程--19--Actor
How to modify icons in VBS or VBE
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
随机推荐
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import 'fmt' func
The 15th youth informatics competition in Shushan District in 2019
DeFi生态NFT流动性挖矿系统开发搭建
876. Intermediate node of linked list
模板_大整数减法_无论大小关系
Rookie post station management system based on C language
Scala basic tutorial -- 14 -- implicit conversion
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
信息学奥赛一本通 1336:【例3-1】找树根和孩子
SSL证书续费相关问题详解
模板_判断素数_开方 / 六素数法
Summary and sorting of 8 pits of redis distributed lock
2021 合肥市信息学竞赛小学组
Basic tutorial of scala -- 16 -- generics
完善的js事件委托
TorchDrug教程
物联网应用技术的就业前景和现状
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
每日一题(2022-07-02)——最低加油次数
基于lex和yacc的词法分析器+语法分析器