div垂直居中
来源:互联网 发布:湖北省融资租赁数据 编辑:程序博客网 时间:2024/05/22 14:16
方法1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
.parent {
width
:
800px
;
height
:
500px
;
border
:
2px
solid
#000
;
position
:
relative
;
}
.child {
width
:
200px
;
height
:
200px
;
margin
:
auto
;
position
:
absolute
;
top
:
0
;
left
:
0
;
bottom
:
0
;
right
:
0
;
background-color
:
red
;
}
方法2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
.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:
1
2
3
4
5
6
7
8
9
10
11
12
13
.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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.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
;
}
0 0
- div 水平居中 垂直居中
- DIV水平居中、垂直居中
- div垂直居中 水平居中
- DIV水平居中、垂直居中
- div垂直居中
- div 垂直居中
- DIV图片垂直居中
- DIV垂直居中
- div内容垂直居中
- Div垂直居中
- div水平垂直居中
- 关于DIV垂直居中
- DIV 水平垂直居中
- 子div垂直居中
- div 水平垂直居中
- div垂直居中
- DIV内容垂直居中
- div 垂直居中
- 求字符串中不包含重复字符的最长子串的长度
- Halcon学习笔记(三)---数据类型
- 图片的二次采样
- linux硬件软件操作系统查看
- CURL常用命令
- div垂直居中
- 解决RedHat中yum命令未注册问题
- springboot3--测试
- Android测试单元学习记录
- 读书笔记 《算法导论》 Appendix
- 矩阵乘法的C语言实现
- #!/usr/bin/env bash和#!/bin/bash区别
- 我的WCF之旅(10):如何在WCF进行Exception Handlingon Handling
- Linux driver model & sysfs