-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4css.html
More file actions
187 lines (177 loc) · 4.95 KB
/
4css.html
File metadata and controls
187 lines (177 loc) · 4.95 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D0ENCWPZL9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-D0ENCWPZL9');
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>4. CSS Units</title>
<style>
body {
font-family: 'Poppins', sans-serif;
background: #1cc9be;
padding: 20px;
color: #222;
}
.section {
background: rgba(255, 255, 255, 0.3);
padding: 20px;
margin-bottom: 30px;
border-radius: 12px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
h2, h3 {
color: #113;
margin-bottom: 10px;
}
p {
font-size: 17px;
margin-bottom: 15px;
line-height: 1.8;
}
textarea, iframe {
width: 100%;
border-radius: 10px;
margin-bottom: 20px;
border: 2px solid white;
}
textarea {
width: 100%;
max-width: 100%;
height: 180px;
font-family: monospace;
font-size: 16px;
padding: 12px;
border: 2px solid white;
border-radius: 10px;
background: rgba(255,248,240,0.4);
resize: vertical;
box-sizing: border-box;
overflow: auto;
}
iframe {
height: 180px;
background: rgba(255,248,240,0.3);
}
button {
padding: 10px 20px;
border: none;
background: #28a745;
color: white;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="section">
<h2>4. CSS Units</h2>
<p><strong>Explanation:</strong> Jab bhi hum kisi element ko size, margin, padding, ya font-size dete hain CSS mein, to humein UNIT lagani padti hai. Jaise 10px, 50%, 2em, 100vw, etc. Unit batata hai ki value ka scale kya hoga.</p>
</div>
<div class="section">
<h3>I. Absolute Units</h3>
<p><strong>Definition:</strong> Ye fixed hote hain, screen ya parent size se nahi badalte. Har jagah same dikhte hain.</p>
<ul>
<li><strong>px (pixels):</strong> Sabse commonly used unit. Ek pixel = screen ka ek point.</li>
<li><strong>cm (centimeter), mm (millimeter), in (inch):</strong> Real world units — print media mein use hote hain.</li>
</ul>
<p><strong>Use:</strong> Jab hume exact control chahiye layout par, jaise border, box size, buttons, etc.</p>
<textarea id="code1">
<!DOCTYPE html>
<html>
<body>
<div style="width: 200px; height: 100px; background: #ffdd57;">
200px wide box
</div>
</body>
</html>
</textarea>
<button onclick="runCode('code1', 'output1')">Run Code</button>
<iframe id="output1"></iframe>
</div>
<div class="section">
<h3>II. Relative Units</h3>
<p><strong>Definition:</strong> Ye apne parent element ya default font size ke basis par kaam karte hain.</p>
<ul>
<li><strong>% (percentage):</strong> Parent element ke size ka percentage.</li>
<li><strong>em:</strong> Current element ke font-size ke base par (1em = current font size).</li>
<li><strong>rem (root em):</strong> Root element (HTML tag) ke font-size ke base par.</li>
</ul>
<p><strong>Use:</strong> Responsive design ke liye best — screen ke size ke hisaab se adjust hota hai.</p>
<textarea id="code2">
<!DOCTYPE html>
<html>
<head>
<style>
.parent {
width: 100%;
background: #fff;
}
.child {
width: 50%;
background: #2196f3;
font-size: 2em; /* 2x current size */
}
</style>
</head>
<body>
<div class="parent">
<div class="child">50% Width + 2em Font</div>
</div>
</body>
</html>
</textarea>
<button onclick="runCode('code2', 'output2')">Run Code</button>
<iframe id="output2"></iframe>
</div>
<div class="section">
<h3>III. Viewport Units</h3>
<p><strong>Definition:</strong> Ye screen ke viewport (visible area) ke hisaab se size dete hain. Super useful in responsive layout.</p>
<ul>
<li><strong>vw (viewport width):</strong> 1vw = 1% of browser width</li>
<li><strong>vh (viewport height):</strong> 1vh = 1% of browser height</li>
<li><strong>vmin, vmax:</strong> Minimum ya maximum of vw and vh</li>
</ul>
<p><strong>Use:</strong> Full screen layouts, banners, headers banane ke liye perfect.</p>
<textarea id="code3">
<!DOCTYPE html>
<html>
<head>
<style>
.box {
width: 100vw;
height: 30vh;
background: #673ab7;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div class="box">30% of screen height</div>
</body>
</html>
</textarea>
<button onclick="runCode('code3', 'output3')">Run Code</button>
<iframe id="output3"></iframe>
</div>
<script>
function runCode(textareaId, iframeId) {
var code = document.getElementById(textareaId).value;
var iframe = document.getElementById(iframeId);
iframe.contentDocument.open();
iframe.contentDocument.write(code);
iframe.contentDocument.close();
}
</script>
</body>
</html>