小div在大div里面 垂直居中
2024-10-20 20:45:34
方法1:
.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:200px;
height:200px;
margin: auto;
position: absolute;
top:; left:; bottom:; right:;
background-color: red;
}
方法2:
.parent {
width:800px;
height:500px;
border:2px solid #000;
display:table-cell;
vertical-align:middle;
text-align: center;
}
.child {
width:200px;
height:200px;
display:inline-block;
background-color: red;
}
方法3:
.parent {
width:800px;
height:500px;
border:2px solid #000;
display:flex;
justify-content:center;
align-items:center;
}
.child {
width:200px;
height:200px;
background-color: red;
}
方法4:
.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:300px;
height:200px;
margin:auto;
position:absolute;/*设定水平和垂直偏移父元素的50%,再根据实际长度将子元素上左挪回一半大小*/
left:50%;
top:50%;
margin-left: -150px;
margin-top:-100px;
background-color: red;
}
最新文章
- ios7 tableview被navigationbar挡住
- XML解析之SAX详解
- systemd
- Iframe跨域_ASP.NET
- 20160314 Servlet 入门
- CentOS在线升级内核
- 八、VueJs 填坑日记之参数传递及内容页面的开发
- Python——匿名函数
- js canvas游戏初级demo-上下左右移动
- ajax查看详细返回信息
- 安装stress模拟linux系统资源消耗
- [Android实例] Android Studio插件-自动根据布局生成Activity等代码1.4 (开源)(申明:来源于网络)
- Windows操作系统下Redis服务安装图文详解
- Android SDK的安装与环境配置
- 【vue】npm run mock &; npm run dev 无法同时运行的解决
- Codeforces Round #296 (Div. 2) B. Error Correct System
- proxy-target-class 作用
- [pixhawk笔记]3-架构概览
- LeetCode -- Sum Root to Leaf NNumbers
- Mysql闪回工具之binlog2sql的原理及其使用
热门文章
- Coding 如何使用 Coding 开发 Coding
- 6.JBoss5.x6.x 反序列化漏洞(CVE-2017-12149)复现
- 5.docker的疑难杂症
- 如何解决Failed to start component [StandardEngine[Catalina].StandardHost[127.0.0.1].StandardContext[]]问题
- Ubuntu16.4下安装Chrome浏览器以及Chromedriver
- OpenStack基础知识-virtualenv工具详解
- 浅谈JavaScript--闭包
- oracle分页计算公式
- spring boot jpa 使用<;S extends T>; List<;S>; findAll(Example<;S>; example)查询数据
- 牛客 PUBG