垂直居中的方法和技巧
来源:互联网 发布:公考推荐书籍知乎 编辑:程序博客网 时间:2024/05/17 07:54
简单的情况text-align:center; vertical-align: middle等,下面是复杂一点的:
// 方法一:已知元素的高宽
CSS:
.content{
background-color:#6699FF;
width:200px;
height:200px;
position: absolute;
top: 50%;
left: 50%;
/* 二分之一的负height,width */
margin-top:-100px ;
margin-left: -100px;
}
//方法二:未知元素的高宽
CSS:
.content{
background-color:#6699FF;
width:200px;
height:200px;
position: absolute;
/* transform: translate(-50%,-50%) 或 margin:auto与四边距相等 */
margin:auto; /无这个就只有top、left起作用/
top: 0;
left: 0;
bottom:0;
right: 0;
}
//3,两个按钮在div中居中,并相距一定距离
div{width: 600px;height: 500px;background-color: rgba(240,240,240,0.9);text-align:
center;}
.button{ width:100px;height: 90px;background-color: #f00;position: relative;top: 50%;
transform: translate(0,-50%) }
.button1{margin-left: 0;margin-right: 100px;}
.button2{margin-right: 0;}
0 0
- 垂直居中的方法和技巧
- CSS 小技巧1——水平居中和垂直居中的方法
- 图片和文字垂直居中的方法
- 垂直居中的方法
- 垂直居中的方法
- 垂直居中的方法
- 垂直居中的方法
- CSS水平居中和垂直居中的各种方法
- CSS水平居中和垂直居中的各种方法
- CSS 样式水平居中和垂直居中的各种方法
- css实现垂直居中和水平居中的方法
- 7种元素的水平居中和垂直居中方法
- 实现水平居中和垂直居中的方法
- [技巧] 未知高度的图片垂直居中方法大全
- 文本垂直居中的方法
- div垂直居中的方法
- css垂直居中的方法
- css垂直居中的方法
- Windows启动项彻底控制
- C#:EXCEL版本与相应dll版本的对应关系
- Linux下BOOST库的安装与使用
- C++ primer 十一 名祢空间
- Spring Boot 44个Starter集成包
- 垂直居中的方法和技巧
- 学生成绩管理
- 支持多语言页面(XML AJAX)
- linux学习之路——第一天(2)
- python学习笔记(20)--类的详解2
- [hihocoder1066]无间道之并查集
- C# DataTable的詳細用法
- 【JZOJ 4923】【NOIP2017提高组模拟12.17】巧克力狂欢
- shu营销通外推软件默认标题