-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSS_center_layout.html
82 lines (71 loc) · 2.3 KB
/
CSS_center_layout.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.simulated_body {
resize: both;
overflow: scroll;
width: 50%;
}
.example {
background-color: #eee;
overflow: hidden;
height: 200px;
}
.cell {
width: 100px;
height: 100px;
background: lightblue;
text-align: center;
}
</style>
<body>
<h3>flex</h3>
<div class="simulated_body">
<section class="example" style="display: flex;justify-content: center;align-items: center;">
<div class="cell">I am a
bucolic
migrant worker but I never walk
backwards.</div>
</section>
</div>
<h3>position+transform</h3>
<div class="simulated_body">
<section class="example" style="position: relative;">
<div class="cell" style="position: absolute;top: 50%;left: 50%;transform:translate(-50%, -50%)">I am a
bucolic
migrant worker but I never walk
backwards.</div>
</section>
</div>
<h3>position+margin:auto</h3>
<div class="simulated_body">
<section class="example" style="position: relative;">
<div class="cell" style="margin: auto;position: absolute;top: 0;left: 0;right: 0;bottom: 0;">I am a bucolic
migrant worker but I never walk
backwards.</div>
</section>
</div>
<h3>position+margin:负值</h3>
<div class="simulated_body">
<section class="example" style="position: relative;">
<div class="cell" style="margin: -50px 0 0 -50px;position: absolute;top: 50%;left:50%">I am a bucolic
migrant worker but I never walk
backwards.</div>
</section>
</div>
<h3>table-cell</h3>
<div class="simulated_body">
<section class="example" style="display: table-cell;vertical-align: middle;width: 500px;">
<div class="cell" style="margin: auto">I am a bucolic
migrant worker but I never walk
backwards.</div>
</section>
</div>
</body>
</html>