-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2css.html
More file actions
245 lines (234 loc) · 5.55 KB
/
2css.html
File metadata and controls
245 lines (234 loc) · 5.55 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!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" />
<title>2. CSS Selectors</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: 'Poppins', sans-serif;
overflow-x: hidden;
background-color: #1cc9be;
}
.section {
background-color: rgba(255, 255, 255, 0.3);
margin: 20px auto;
padding: 20px;
border-radius: 12px;
width: 90%;
max-width: 1000px;
box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}
h2, h3 {
color: #333;
margin-bottom: 15px;
}
p {
font-size: 18px;
margin-bottom: 20px;
line-height: 1.7;
}
textarea {
width: 100%;
height: 150px;
font-family: monospace;
font-size: 16px;
padding: 10px;
border: 2px solid white;
border-radius: 8px;
margin-top: 10px;
margin-bottom: 10px;
background: rgba(255,248,240,0.4);
}
button {
background-color: #28a745;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 8px;
cursor: pointer;
margin-bottom: 20px;
}
iframe {
width: 100%;
height: 150px;
background: rgba(255,248,240,0.4);
border: 2px solid white;
border-radius: 8px;
margin-top: 15px;
}
</style>
</head>
<body>
<div class="section">
<h2>2. CSS Selectors</h2>
<h3>1. Element Selector (Tag Selector)</h3>
<p><strong>Explanation:</strong> Ye specific tag (jaise <code>h1</code>, <code>p</code>) ko target karta hai aur unke upar style lagata hai.</p>
<textarea id="sel1">
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
</textarea>
<button onclick="runCode('sel1', 'out1')">Run Code</button>
<iframe id="out1"></iframe>
<h3>2. Class Selector (.)</h3>
<p><strong>Explanation:</strong> Kisi bhi element me class attribute ke through styling lagayi ja sakti hai. Class ke liye <code>.</code> use hota hai.</p>
<textarea id="sel2">
<!DOCTYPE html>
<html>
<head>
<style>
.highlight {
background-color: yellow;
}
</style>
</head>
<body>
<p class="highlight">This is highlighted text.</p>
</body>
</html>
</textarea>
<button onclick="runCode('sel2', 'out2')">Run Code</button>
<iframe id="out2"></iframe>
<h3>3. ID Selector (#)</h3>
<p><strong>Explanation:</strong> ID selector kisi specific element ko style karta hai jiska unique ID hota hai. Use karte hain <code>#</code>.</p>
<textarea id="sel3">
<!DOCTYPE html>
<html>
<head>
<style>
#unique {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<p id="unique">This is a unique paragraph.</p>
</body>
</html>
</textarea>
<button onclick="runCode('sel3', 'out3')">Run Code</button>
<iframe id="out3"></iframe>
<h3>4. Universal Selector (*)</h3>
<p><strong>Explanation:</strong> Sabhi elements ko ek sath target karne ke liye <code>*</code> use hota hai.</p>
<textarea id="sel4">
<!DOCTYPE html>
<html>
<head>
<style>
* {
font-family: Arial;
color: darkgreen;
}
</style>
</head>
<body>
<h1>Hello</h1>
<p>Every element is styled</p>
</body>
</html>
</textarea>
<button onclick="runCode('sel4', 'out4')">Run Code</button>
<iframe id="out4"></iframe>
<h3>5. Group Selector</h3>
<p><strong>Explanation:</strong> Ek sath multiple selectors ko group me style karne ke liye comma use karte hain.</p>
<textarea id="sel5">
<!DOCTYPE html>
<html>
<head>
<style>
h1, p {
text-align: center;
color: teal;
}
</style>
</head>
<body>
<h1>This is Heading</h1>
<p>This is Paragraph</p>
</body>
</html>
</textarea>
<button onclick="runCode('sel5', 'out5')">Run Code</button>
<iframe id="out5"></iframe>
<h3>6. Attribute Selector</h3>
<p><strong>Explanation:</strong> Jo elements kisi specific attribute (jaise type, href) ko hold karte hain unhe target karta hai.</p>
<textarea id="sel6">
<!DOCTYPE html>
<html>
<head>
<style>
input[type="text"] {
background-color: lightyellow;
}
</style>
</head>
<body>
<input type="text" value="Text Field">
<input type="submit" value="Submit">
</body>
</html>
</textarea>
<button onclick="runCode('sel6', 'out6')">Run Code</button>
<iframe id="out6"></iframe>
<h3>7. Pseudo-classes & Pseudo-elements</h3>
<p><strong>Explanation:</strong> Ye special states ya parts of elements ko style karne ke liye hote hain. Jaise hover, first-line etc.</p>
<textarea id="sel7">
<!DOCTYPE html>
<html>
<head>
<style>
a:hover {
color: red;
}
p::first-line {
font-weight: bold;
}
</style>
</head>
<body>
<a href="#">Hover me</a>
<p>This paragraph will show bold first line only.</p>
</body>
</html>
</textarea>
<button onclick="runCode('sel7', 'out7')">Run Code</button>
<iframe id="out7"></iframe>
</div>
<script>
function runCode(textareaId, iframeId) {
const code = document.getElementById(textareaId).value;
const iframe = document.getElementById(iframeId);
iframe.contentDocument.open();
iframe.contentDocument.write(code);
iframe.contentDocument.close();
}
</script>
</body>
</html>