-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS-box-sizing.html
104 lines (92 loc) · 2.3 KB
/
CSS-box-sizing.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The box-sizing property</title>
<style>
/*
*{
box-sizing: border-box; [applies box-sizing to all elements]
}
*/
.div1 {
border: 3px dashed red;
width: 300px;
height: 110px;
padding: 23px;
}
.div2 {
border: 3px dashed rgb(0, 255, 55);
width: 300px;
height: 110px;
}
hr {
height: 10px;
width: 120%;
background-color: red;
}
h1 {
text-align: center;
color: royalblue;
}
.div3 {
border: 3px dashed red;
width: 300px;
height: 110px;
box-sizing: border-box;
/*To include padding and border in an element's total width and height.*/
}
.div4 {
border: 3px dashed rgb(0, 255, 55);
width: 300px;
height: 110px;
padding: 23px;
box-sizing: border-box;
}
.container {
width: 100%;
border: 5px solid black;
}
.box {
width: 50%;
border: 5px solid red;
float: left;
}
.box2 {
box-sizing: border-box;
width: 50%;
border: 5px solid red;
float: left;
}
</style>
</head>
<body>
<p> box-sizing: Defines how the width and height of an element are calculated: should they include padding and
borders, or not</p>
<h1>Without Box-Sizing</h1>
<div class="div1">This Div is Bigger (W:300px and H:110px & Padding:23px)</div>
<br>
<div class="div2">This Div is Smaller (W:300px and H:110px) </div>
<hr>
<h1>With Box-Sizing</h1>
<div class="div3">Both divs are the same size now!</div>
<br>
<div class="div4">Miracle of box-sizing!</div>
<hr>
<h1>Without Box-Sizing</h1>
<div class="container">
<div class="box">This div occupies the left half</div>
<div class="box">This div occupies the right half</div>
<div style="clear: both;"></div>
</div>
<br>
<h1>With Box-Sizing</h1>
<div class="container">
<div class="box2">This div occupies the left half</div>
<div class="box2">This div occupies the right half</div>
<div style="clear: both;"></div>
<!--he clear property specifies on which sides of an element floating elements are not allowed to float.-->
</div>
</body>
</html>