-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition-1-demo.html
More file actions
441 lines (404 loc) · 15.7 KB
/
position-1-demo.html
File metadata and controls
441 lines (404 loc) · 15.7 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Position Tulajdonságok</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
background-color: #f0f0f0;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1, h2 {
color: #333;
margin-bottom: 20px;
}
.position-demo {
margin: 40px 0;
padding: 20px;
border: 2px solid #ddd;
border-radius: 8px;
background-color: #fff;
}
.demo-box {
width: 400px;
height: 400px;
border: 2px solid #666;
margin: 20px 0;
position: relative;
background-color: #f8f8f8;
}
.element {
width: 80px;
height: 80px;
background-color: #4CAF50;
color: white;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-size: 14px;
transition: all 0.3s ease;
}
.parent {
width: 200px;
height: 200px;
background-color: #f1f1f1;
border: 2px dashed #999;
margin: 20px;
padding: 10px;
position: relative;
}
.explanation {
background-color: #e9f5f9;
padding: 15px;
border-left: 4px solid #2196F3;
margin: 20px 0;
}
.controls {
margin: 20px 0;
padding: 10px;
background-color: #f5f5f5;
border-radius: 5px;
}
button {
padding: 8px 16px;
margin: 5px;
border: none;
border-radius: 4px;
background-color: #2196F3;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #1976D2;
}
.code-example {
background-color: #f8f9fa;
padding: 15px;
border-radius: 5px;
font-family: monospace;
margin: 10px 0;
}
/* Specific position demonstrations */
#static-demo .element {
background-color: #2196F3;
}
#relative-demo .element {
background-color: #4CAF50;
}
#absolute-demo .element {
background-color: #FF5722;
}
#fixed-demo .element {
background-color: #9C27B0;
}
#sticky-demo .element {
background-color: #FF9800;
}
.coordinates {
position: absolute;
bottom: 5px;
right: 5px;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>CSS Position Tulajdonságok Bemutatása</h1>
<div class="explanation">
<p>A CSS position tulajdonság meghatározza, hogy egy elem hogyan helyezkedik el a dokumentumban.
Ez az oldal bemutatja az összes position értéket és azok működését.</p>
</div>
<!-- Static Position -->
<div class="position-demo" id="static-demo">
<h2>Position: Static</h2>
<div class="explanation">
<p>Ez a pozíció a weboldalak alapértelmezett beállítása. Ha nem állítunk be semmilyen pozíciót, az elem automatikusan statikus lesz. A statikus elem mindig a normál dokumentumfolyamot követi, így az olyan tulajdonságok, mint a top, right, bottom vagy left, nem módosítják az elhelyezkedését.</p>
</div>
<div class="demo-box">
<div class="element">
Static
</div>
</div>
<div class="code-example">
.element {
position: static;
}
</div>
</div>
<!-- Relative Position -->
<div class="position-demo" id="relative-demo">
<h2>Position: Relative</h2>
<div class="explanation">
<p>A relative pozíció használatával az elemet elmozdíthatjuk a normál helyéről anélkül, hogy az eredeti helyét a dokumentumfolyamban elveszítené. Ez azt jelenti, hogy az elmozdított elem 'árnyéka' ott marad, ahol az eredetileg lett volna. Az elmozdítást a top, right, bottom és left tulajdonságokkal szabályozhatjuk.</p>
</div>
<div class="controls">
<button onclick="moveRelative('top')">Top: 50px</button>
<button onclick="moveRelative('right')">Right: 50px</button>
<button onclick="moveRelative('bottom')">Bottom: 50px</button>
<button onclick="moveRelative('left')">Left: 50px</button>
<button onclick="resetRelative()">Alaphelyzet</button>
</div>
<div class="demo-box">
<div class="element" id="relative-element">
Relative
<div class="coordinates"></div>
</div>
</div>
<div class="code-example">
.element {
position: relative;
/* Az aktuális offset értékek itt jelennek meg */
}
</div>
</div>
<!-- Absolute Position -->
<div class="position-demo" id="absolute-demo">
<h2>Position: Absolute</h2>
<div class="explanation">
<p>Az absolute pozíció eltávolítja az elemet a normál dokumentumfolyamból, így az már nem befolyásolja a többi elem elhelyezkedését. Az absolute pozícionált elem elhelyezése a legközelebbi szülőelemhez viszonyítva történik, amelynek pozíciója nem static. Ha nincs ilyen szülőelem, akkor az elhelyezés az egész oldalhoz, vagyis a html elemhez viszonyítva történik.</p>
</div>
<div class="controls">
<button onclick="moveAbsolute('top')">Top: 0</button>
<button onclick="moveAbsolute('right')">Right: 0</button>
<button onclick="moveAbsolute('bottom')">Bottom: 0</button>
<button onclick="moveAbsolute('left')">Left: 0</button>
<button onclick="moveAbsolute('center')">Középre</button>
<button onclick="resetAbsolute()">Alaphelyzet</button>
</div>
<div class="demo-box">
<div class="parent">
Szülő elem (relative)
<div class="element" id="absolute-element">
Absolute
<div class="coordinates"></div>
</div>
</div>
</div>
<div class="code-example">
.parent {
position: relative;
}
.element {
position: absolute;
/* Az aktuális offset értékek itt jelennek meg */
}
</div>
</div>
<!-- Fixed Position -->
<div class="position-demo" id="fixed-demo">
<h2>Position: Fixed</h2>
<div class="explanation">
<p>A fixed pozíció rögzíti az elemet a böngészőablak (viewport) egy meghatározott pontjára. Az elem mindig az adott pozíción marad, még akkor is, ha a felhasználó az oldalt görgeti. Ez különösen hasznos például fejlécek vagy láblécek rögzítésére.</p>
</div>
<div class="controls">
<button onclick="moveFixed('top')">Top: 0</button>
<button onclick="moveFixed('right')">Right: 0</button>
<button onclick="moveFixed('bottom')">Bottom: 0</button>
<button onclick="moveFixed('left')">Left: 0</button>
<button onclick="resetFixed()">Visszaállítás</button>
</div>
<div class="demo-box">
<div class="element" id="fixed-element">
Fixed
<div class="coordinates"></div>
</div>
</div>
<div class="code-example">
.element {
position: fixed;
/* Az aktuális offset értékek itt jelennek meg */
}
</div>
</div>
<!-- Sticky Position -->
<div class="position-demo" id="sticky-demo">
<h2>Position: Sticky</h2>
<div class="explanation">
<p>A sticky pozíció egy speciális beállítás, amely ötvözi a relative és a fixed pozíciók tulajdonságait. Az elem először a normál dokumentumfolyamot követi (relative), de amikor a görgetés során eléri a megadott offset értéket (például top: 20px), az adott ponton rögzül (fixed) a képernyőhöz. Ez különösen hasznos például navigációs sávoknál.</p>
</div>
<div class="demo-box" style="height: 300px; overflow-y: scroll;">
<div style="height: 2000px; background: linear-gradient(to bottom, #f0f0f0 0%, #e0e0e0 100%); padding: 20px;">
<div style="height: 200px; text-align: center; padding-top: 80px;">👆 Görgess lefelé</div>
<div class="element" id="sticky-element" style="position: sticky; top: 20px;">
Sticky
<div class="coordinates"></div>
</div>
<div style="height: 1500px; display: flex; flex-direction: column; justify-content: space-around; padding: 20px; text-align: center;">
<p>Görgess tovább...</p>
<p>Még lejjebb...</p>
<p>A sticky elem követi a görgetést!</p>
<p>Majdnem a végén...</p>
<p>👋 Vége a görgethető területnek</p>
</div>
</div>
</div>
<div class="code-example">
.element {
position: sticky;
top: 20px;
}
</div>
</div>
</div>
<script>
// Relative position controls
function moveRelative(direction) {
const element = document.getElementById('relative-element');
// Először töröljük az összes pozícionáló tulajdonságot
element.style = 'position: relative;';
element.style.top = '';
element.style.right = '';
element.style.bottom = '';
element.style.left = '';
switch(direction) {
case 'top':
element.style.top = '50px';
break;
case 'right':
element.style.left = '50px';
break;
case 'bottom':
element.style.bottom = '50px';
break;
case 'left':
element.style.left = '-50px';
break;
}
updateCoordinates(element);
}
function resetRelative() {
const element = document.getElementById('relative-element');
element.style = 'position: relative;';
updateCoordinates(element);
}
// Absolute position controls
function moveAbsolute(direction) {
const element = document.getElementById('absolute-element');
const parent = element.closest('.parent');
element.style = 'position: absolute;';
switch(direction) {
case 'top':
element.style.top = '0';
element.style.left = '0';
element.style.right = '';
element.style.bottom = '';
break;
case 'right':
element.style.top = '0';
element.style.right = '0';
element.style.left = '';
element.style.bottom = '';
break;
case 'bottom':
element.style.bottom = '0';
element.style.right = '0';
element.style.top = '';
element.style.left = '';
break;
case 'left':
element.style.bottom = '0';
element.style.left = '0';
element.style.top = '';
element.style.right = '';
break;
case 'center':
element.style.top = '50%';
element.style.left = '50%';
element.style.right = '';
element.style.bottom = '';
element.style.transform = 'translate(-50%, -50%)';
break;
}
updateCoordinates(element);
}
function resetAbsolute() {
const element = document.getElementById('absolute-element');
element.style = 'position: absolute;';
updateCoordinates(element);
}
// Fixed position controls
function moveFixed(direction) {
const element = document.getElementById('fixed-element');
element.style = 'position: fixed;';
switch(direction) {
case 'top':
element.style.top = '0';
element.style.left = '20px';
break;
case 'right':
element.style.top = '20px';
element.style.right = '0';
break;
case 'bottom':
element.style.bottom = '0';
element.style.right = '20px';
break;
case 'left':
element.style.bottom = '20px';
element.style.left = '0';
break;
}
updateCoordinates(element);
}
function resetFixed() {
const element = document.getElementById('fixed-element');
element.style = 'position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);';
updateCoordinates(element);
}
// Update coordinates display
function updateCoordinates(element) {
const coords = element.querySelector('.coordinates');
const style = window.getComputedStyle(element);
const values = {
top: style.top,
right: style.right,
bottom: style.bottom,
left: style.left
};
let text = '';
for (let [prop, value] of Object.entries(values)) {
if (value !== 'auto') {
text += `${prop}: ${value} `;
}
}
coords.textContent = text;
// Update code example
const demoBox = element.closest('.position-demo');
const codeExample = demoBox.querySelector('.code-example');
let codeText = `.element {\n position: ${style.position};`;
for (let [prop, value] of Object.entries(values)) {
if (value !== 'auto') {
codeText += `\n ${prop}: ${value};`;
}
}
if (style.transform !== 'none') {
codeText += `\n transform: ${style.transform};`;
}
codeText += '\n}';
codeExample.textContent = codeText;
}
// Initialize coordinates
document.querySelectorAll('.element').forEach(updateCoordinates);
</script>
</body>
</html>