-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS-vertical-align-v2.html
114 lines (110 loc) · 2.55 KB
/
CSS-vertical-align-v2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vertical Alignment V2</title>
<style>
body{
background-color: coral;
}
header{
border: 1px solid rosybrown;
width: 48%;
margin: 20px 0;
padding-top: 20px;
padding-bottom: 20px;
/* equal padding-top and padding-bottom to make element vertically centered */
}
span h2{
border: 1px solid rebeccapurple;
margin: 20px 0;
width: 48%;
padding:30px;
height: 30px;
line-height: 30px;
white-space: nowrap;
/*equal line-height and the height will center the text. */
}
table {
background: white;
width: 240px;
border-collapse: separate;
margin: 20px;
height: 250px;
/* default is vertical-align: middle; */
}
table td{
color: whitesmoke;
background-color: black;
padding: 20px;
border: 10px solid white;
}
.center-table{
background-color: black;
width: 240px;
height: 250px;
margin: 20px;
display: table;
}
.center-table p{
display: table-cell;
vertical-align: middle;
margin: 0;
color: white;
padding: 20px;
border: 10px solid white;
}
.ghost-center{
background: white;
width: 240px;
height: 200px;
margin: 20px;
color: rgb(17, 245, 131);
resize: vertical;
overflow: auto;
padding: 20px;
position: relative;
}
.ghost-center::before {
content: " ";
display: inline-block;
height: 100%;
width: 1%;
vertical-align: middle;
}
.ghost-center p {
display: inline-block;
vertical-align: middle;
width: 190px;
margin: 0;
padding: 20px;
background: black;
}
</style>
</head>
<body>
<header>
<h1>
welcome to the world of CSS!
</h1>
</header>
<span>
<h2>Never stop practicing!</h2>
</span>
<br><hr>
<table>
<tr>
<td>
I'm vertically centered multiple lines of text in a real table cell.
</td>
</tr>
</table>
<div class="center-table">
<p>I'm vertically centered multiple lines of text in a CSS-created table layout.</p>
</div>
<div class="ghost-center">
<p>I'm vertically centered multiple lines of text in a container. Centered with a ghost pseudo element</p>
</div>
</body>
</html>