-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8css.html
More file actions
213 lines (201 loc) · 6.95 KB
/
8css.html
File metadata and controls
213 lines (201 loc) · 6.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
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
<!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>8. Positioning & Display in CSS</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background-color: #1cc9be;
padding: 20px;
}
.section {
background: rgba(255, 255, 255, 0.3);
padding: 20px;
border-radius: 15px;
max-width: 1000px;
margin: auto;
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
h2, h3 {
color: #349;
margin-bottom: 15px;
}
p {
font-size: 18px;
margin-bottom: 15px;
line-height: 1.6;
}
textarea, iframe {
width: 100%;
height: 160px;
font-size: 16px;
padding: 10px;
margin: 10px 0 20px;
border-radius: 10px;
border: 2px solid white;
background: rgba(255,248,240,0.4);
font-family: monospace;
}
iframe {
margin-top: 10px;
}
button {
background: #007bff;
color: #fff;
border: none;
padding: 8px 20px;
font-size: 15px;
font-weight: 500;
border-radius: 8px;
cursor: pointer;
margin-bottom: 20px;
transition: all 0.3s ease-in-out;
position: relative;
overflow: hidden;
}
button::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(120deg, #00bcd4, #2196f3);
transition: all 0.4s ease;
z-index: -1;
}
button:hover::before {
left: 0;
}
button:hover {
color: #fff;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
transform: translateY(-1px);
}
button:active {
transform: scale(0.95);
box-shadow: none;
}
</style>
</head>
<body>
<div class="section">
<h2>8. Positioning & Display in CSS</h2>
<h3>1. position: static</h3>
<p><strong>Explanation:</strong> Ye CSS ka default position hota hai. Koi special positioning nahi hoti. Element page me normal flow me appear hota hai.</p>
<textarea id="code1">
<div style="position: static; background: lightcoral; padding: 20px;">
Ye static position hai (default).
</div>
</textarea>
<button onclick="runCode('code1', 'output1')">Run Code</button>
<iframe id="output1"></iframe>
<h3>2. position: relative</h3>
<p>Element apni original jagah se shift ho sakta hai using <code>top</code>, <code>left</code>, <code>right</code>, <code>bottom</code>. Lekin uski original space remain karti hai.</p>
<textarea id="code2">
<div style="position: relative; top: 20px; left: 20px; background: orange; padding: 20px;">
Relative position se element shift ho gaya.
</div>
</textarea>
<button onclick="runCode('code2', 'output2')">Run Code</button>
<iframe id="output2"></iframe>
<h3>3. position: absolute</h3>
<p>Ye element apne closest <code>relative</code> ancestor ke respect me position leta hai. Agar na mile to <code>body</code> ke respect me hota hai.</p>
<textarea id="code3">
<div style="position: relative; height: 150px; background: lightgray;">
<div style="position: absolute; top: 10px; right: 10px; background: steelblue; color: white; padding: 10px;">
Absolute Box
</div>
</div>
</textarea>
<button onclick="runCode('code3', 'output3')">Run Code</button>
<iframe id="output3"></iframe>
<h3>4. position: fixed</h3>
<p>Ye element viewport me fix rahta hai. Page scroll hone ke baad bhi wahi dikhta hai.</p>
<textarea id="code4">
<div style="position: fixed; bottom: 10px; right: 10px; background: purple; color: white; padding: 10px;">
Fixed Position Box
</div>
<p style="height: 400px;">Scroll karke dekho...</p>
</textarea>
<button onclick="runCode('code4', 'output4')">Run Code</button>
<iframe id="output4"></iframe>
<h3>5. position: sticky</h3>
<p>Scroll karte waqt ye element chipak jata hai kisi position par. Useful for headers.</p>
<textarea id="code5">
<div style="position: sticky; top: 0; background: gold; padding: 10px;">
Sticky Header
</div>
<p style="height: 400px;">Scroll down to test sticky behavior.</p>
</textarea>
<button onclick="runCode('code5', 'output5')">Run Code</button>
<iframe id="output5"></iframe>
<h3>6. z-index</h3>
<p><code>z-index</code> use hota hai layers define karne ke liye — kaunsa element upar ya niche dikhna chahiye.</p>
<textarea id="code6">
<div style="position: relative; z-index: 1; background: red; color: white; padding: 20px; margin-top: 30px;">
Z-index: 1
</div>
<div style="position: relative; z-index: 2; background: green; color: white; padding: 20px; margin-top: -40px;">
Z-index: 2 (Upar)
</div>
</textarea>
<button onclick="runCode('code6', 'output6')">Run Code</button>
<iframe id="output6"></iframe>
<h3>7. Display: block, inline, inline-block, none</h3>
<p><code>display</code> property se element ka layout behavior define hota hai.</p>
<textarea id="code7">
<div style="display: block; background: #cce; padding: 10px;">Block Element</div>
<span style="display: inline; background: #ecc;">Inline</span>
<div style="display: inline-block; background: #cec; padding: 10px;">Inline-Block</div>
</textarea>
<button onclick="runCode('code7', 'output7')">Run Code</button>
<iframe id="output7"></iframe>
<h3>8. display: flex</h3>
<p><code>flex</code> layout horizontal ya vertical direction me elements ko align karta hai easily.</p>
<textarea id="code8">
<div style="display: flex; gap: 10px;">
<div style="background: salmon; padding: 20px;">Item 1</div>
<div style="background: skyblue; padding: 20px;">Item 2</div>
</div>
</textarea>
<button onclick="runCode('code8', 'output8')">Run Code</button>
<iframe id="output8"></iframe>
<h3>9. display: grid</h3>
<p><code>grid</code> layout rows & columns me items ko arrange karta hai. Ye complex layout banane me best hai.</p>
<textarea id="code9">
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;">
<div style="background: lightgreen; padding: 20px;">Grid 1</div>
<div style="background: lightcoral; padding: 20px;">Grid 2</div>
</div>
</textarea>
<button onclick="runCode('code9', 'output9')">Run Code</button>
<iframe id="output9"></iframe>
</div>
<script>
function runCode(textareaId, iframeId) {
const code = document.getElementById(textareaId).value;
const iframe = document.getElementById(iframeId);
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write(code);
doc.close();
}
</script>
</body>
</html>