-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcenter-div.html
141 lines (122 loc) · 2.36 KB
/
center-div.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<style>
/*.grid {
display: grid;
justify-items: center;
margin-top:2px;
}
.grid h2{
background:#f0e68c;
padding:4px;
color:black;
}
body{
font-family: 'Dancing Script', cursive;
background-color:#0A4A8A;
font-size: .8em;
}
h1{
text-align:center;
color:white;
}
.text{
text-align:center;
background:green;
color:white;
width:400px;
margin: 0 auto;
/* These are for design */
/*background:green;
color:white;
padding:5px;*/
}
.flexbox_1{
display:flex;
justify-content:center;
}
.multiple_margin{
width:400px;
margin:0 auto;
}
.red{
background:red;
}
.yellow{
background:yellow;
}
.flexbox_2{
display:flex;
justify-content:center;
}
.white{
width:200px;
height:200px;
background:white;
font-size: 2em;
text-align:center;
}
.pink{
width:200px;
height:200px;
background:pink;
font-size:2em;
text-align:center;
}
.absolute_positioning{
position:absolute;
left: 50%;
top: 80%;
transform: translate(-50%, -5%);
/* for extra designs */
background-color:black;
color:white;
width: 200px;
height: 50px;
font-size:1.5em;
}
*/
</style>
</head>
<body>
<!-- <h1>Horizontal Centering Tutorial (Text-align Method)</h1>
<div class="text">
<h2>Text-align on block Method</h2>
</div>
<div class="flexbox_1">
<img src="https://onaircode.com/wp-content/uploads/2017/11/logo-new-color-1.png">
</div>
<div class="outer-div">
<div class="inner-div"></div>
</div>
<div class="multiple_margin">
<div class="red">Child 1</div>
<div class="yellow">Child 2</div>
</div>
<div class="flexbox_2">
<div class="white">Child 1 Using Flex-box Method</div>
<div class="pink">Child 2 Using Flex-box Method </div>
</div>
<div class="absolute_positioning">
Absolute Positioning
</div>
<!-- <div class="grid">
<h3>Center Alignment with Grid</h3>
</div> -->
<div class="grid">
<h2>Center Alignment with Grid</h2>
</div>
-->
<div id="dynamic_change">
<p> Javascript code will change the CSS of this element</p>
</div>
<button onClick="align_center()">Click me align center</button>
</body>
<script type="text/javascript">
function align_center(){
document.getElementById('dynamic_change').style.display = "grid";
document.getElementById('dynamic_change').style.justifyItems = "center";
}
</script>
</html>