9.如何让一个div 上下左右居中?【CS
2024-08-21 10:15:41
方法1:【绝对定位50%-本身50%】
position:absolute; left:50%; top:50%;
transform: translate(-50%,-50%);
.div1{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position:absolute; left:50%; top:50%;/*绝对定位*/
transform: translate(-50%,-50%);
/*translate(x,y) 括号的百分比数据,会以本身的长宽做参考,比如,本身的长为100px,高为100px. 那填(50%,50%)就是向右,向下移动50px,添加负号就是向着相反的方向移动*/
} <div class="div1"></div>
方法2:不太懂
.div2{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position: absolute;
left:0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
}
<div class="div2"></div>
方法3:【绝对定位50%-本身50%】
.div3{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#9f9;
position: absolute;
left: 50%;
top:50%;
margin-left:-200px;
margin-top: -200px;
}
<div class="div3"></div>
最新文章
- 在Unity中使用UGUI修改Mesh绘制几何图形
- [.NET领域驱动设计实战系列]专题一:前期准备之EF CodeFirst
- iOS常用手势识别器
- Fliwer:监控植物状态 实现远程浇水
- ios 学习总结之动画(转)
- ZooKeeper典型应用场景一览
- studio--如何将Eclipse中的项目迁移到Android Studio 中
- C:指针
- centos 安装git server
- 复制表的sql语句
- [HTML5] Input accepts only 6 number characters
- 系统调用和中断处理的异同(以Linux MIPS为例)
- JavaScript详解
- scrapy使用PhantomJS爬取数据
- JAVA中正则表达式总结
- htop的安装和使用
- bzoj 4621: Tc605 动态规划
- leetcode-algorithms-34 Find First and Last Position of Element in Sorted Array
- Chapter 3 Phenomenon——16
- 【Coursera】支持向量机
热门文章
- webpack构建篇
- mocha单元测试简易教程
- 【2019.09.19】数独(Sudoku)游戏之我见(软工实践第三次作业)
- Invalid bound statement (not found) 错误原因
- [转]无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
- 共线性图 | Alluvial Diagrams | Parallel plot | Parallel Coordinates Plot
- python 代码性能分析 库
- Cucumber介绍
- IntelliJ IDEA添加JavaDOC注释 方法 快捷键
- Component &#39;TABCTL32.OCX&#39;错误的处理方法