fix some z index error

#2
by Naveen671 - opened
Files changed (1) hide show
  1. app.py +267 -9
app.py CHANGED
@@ -124,6 +124,34 @@ def determine_style_theme(prompt: str) -> str:
124
  else:
125
  return 'modern'
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  def generate_css_from_prompt(prompt: str, components: dict) -> str:
128
  """Generate CSS based on the design requirements."""
129
 
@@ -158,7 +186,7 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
158
  }
159
  """
160
 
161
- # Add component-specific styles
162
  if components['has_header']:
163
  css += """
164
  .header {
@@ -167,7 +195,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
167
  padding: 1rem 0;
168
  position: sticky;
169
  top: 0;
170
- z-index: 100;
 
171
  }
172
 
173
  .nav {
@@ -177,6 +206,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
177
  max-width: 1200px;
178
  margin: 0 auto;
179
  padding: 0 2rem;
 
 
180
  }
181
 
182
  .nav ul {
@@ -189,6 +220,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
189
  color: white;
190
  text-decoration: none;
191
  transition: color 0.3s;
 
 
192
  }
193
 
194
  .nav a:hover {
@@ -203,16 +236,41 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
203
  color: white;
204
  text-align: center;
205
  padding: 8rem 2rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
207
 
208
  .hero h1 {
209
  font-size: 3rem;
210
  margin-bottom: 1rem;
 
 
211
  }
212
 
213
  .hero p {
214
  font-size: 1.2rem;
215
  margin-bottom: 2rem;
 
 
216
  }
217
 
218
  .btn {
@@ -222,11 +280,17 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
222
  padding: 1rem 2rem;
223
  text-decoration: none;
224
  border-radius: 5px;
225
- transition: background-color 0.3s;
 
 
 
 
226
  }
227
 
228
  .btn:hover {
229
  background-color: #c0392b;
 
 
230
  }
231
  """
232
 
@@ -236,6 +300,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
236
  padding: 4rem 2rem;
237
  max-width: 1200px;
238
  margin: 0 auto;
 
 
239
  }
240
 
241
  .cards-grid {
@@ -243,6 +309,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
243
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
244
  gap: 2rem;
245
  margin-top: 2rem;
 
 
246
  }
247
 
248
  .card {
@@ -250,12 +318,44 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
250
  border-radius: 10px;
251
  padding: 2rem;
252
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
253
- transition: transform 0.3s, box-shadow 0.3s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
255
 
256
  .card:hover {
257
  transform: translateY(-5px);
258
- box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  }
260
  """
261
 
@@ -264,6 +364,8 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
264
  .form-section {
265
  padding: 4rem 2rem;
266
  background-color: #f8f9fa;
 
 
267
  }
268
 
269
  .form-container {
@@ -273,16 +375,22 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
273
  padding: 2rem;
274
  border-radius: 10px;
275
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 
 
276
  }
277
 
278
  .form-group {
279
  margin-bottom: 1.5rem;
 
 
280
  }
281
 
282
  .form-group label {
283
  display: block;
284
  margin-bottom: 0.5rem;
285
  font-weight: bold;
 
 
286
  }
287
 
288
  .form-group input,
@@ -292,13 +400,24 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
292
  border: 1px solid #ddd;
293
  border-radius: 5px;
294
  font-size: 1rem;
 
 
 
 
295
  }
296
 
297
  .form-group input:focus,
298
  .form-group textarea:focus {
299
  outline: none;
300
  border-color: #3498db;
301
- box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
 
 
 
 
 
 
 
302
  }
303
  """
304
 
@@ -310,10 +429,17 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
310
  text-align: center;
311
  padding: 2rem 0;
312
  margin-top: 4rem;
 
 
 
 
 
 
 
313
  }
314
  """
315
 
316
- # Add animations if requested
317
  if components['has_animation']:
318
  css += """
319
  @keyframes fadeInUp {
@@ -327,12 +453,144 @@ def generate_css_from_prompt(prompt: str, components: dict) -> str:
327
  }
328
  }
329
 
 
 
 
 
 
 
 
 
 
 
 
330
  .animate-on-scroll {
331
- animation: fadeInUp 0.6s ease-out;
 
 
 
 
 
 
 
 
 
 
 
332
  }
333
  """
334
 
335
- return css
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  def generate_html_structure(prompt: str, components: dict) -> str:
338
  """Generate HTML structure based on components."""
 
124
  else:
125
  return 'modern'
126
 
127
+ def fix_zindex_conflicts(css_content: str) -> str:
128
+ """Fix common z-index conflicts in generated CSS."""
129
+
130
+ # Define z-index hierarchy for common components
131
+ zindex_hierarchy = {
132
+ 'modal': 9999,
133
+ 'modal-overlay': 9998,
134
+ 'dropdown': 200,
135
+ 'tooltip': 300,
136
+ 'header': 1000,
137
+ 'nav': 1001,
138
+ 'sticky': 100,
139
+ 'card-hover': 13,
140
+ 'card': 12,
141
+ 'form': 10,
142
+ 'content': 1,
143
+ 'background': -1
144
+ }
145
+
146
+ # Add z-index management comment
147
+ fixed_css = """
148
+ /* Z-Index Management System */
149
+ /* Modal: 9999, Dropdowns: 200-299, Headers: 1000-1099, Content: 1-99, Background: -1 */
150
+
151
+ """ + css_content
152
+
153
+ return fixed_css
154
+
155
  def generate_css_from_prompt(prompt: str, components: dict) -> str:
156
  """Generate CSS based on the design requirements."""
157
 
 
186
  }
187
  """
188
 
189
+ # Add component-specific styles with proper z-index management
190
  if components['has_header']:
191
  css += """
192
  .header {
 
195
  padding: 1rem 0;
196
  position: sticky;
197
  top: 0;
198
+ z-index: 1000;
199
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
200
  }
201
 
202
  .nav {
 
206
  max-width: 1200px;
207
  margin: 0 auto;
208
  padding: 0 2rem;
209
+ position: relative;
210
+ z-index: 1001;
211
  }
212
 
213
  .nav ul {
 
220
  color: white;
221
  text-decoration: none;
222
  transition: color 0.3s;
223
+ position: relative;
224
+ z-index: 1002;
225
  }
226
 
227
  .nav a:hover {
 
236
  color: white;
237
  text-align: center;
238
  padding: 8rem 2rem;
239
+ position: relative;
240
+ z-index: 1;
241
+ overflow: hidden;
242
+ }
243
+
244
+ .hero::before {
245
+ content: '';
246
+ position: absolute;
247
+ top: 0;
248
+ left: 0;
249
+ right: 0;
250
+ bottom: 0;
251
+ background: inherit;
252
+ z-index: -1;
253
+ }
254
+
255
+ .hero-content {
256
+ position: relative;
257
+ z-index: 2;
258
+ max-width: 800px;
259
+ margin: 0 auto;
260
  }
261
 
262
  .hero h1 {
263
  font-size: 3rem;
264
  margin-bottom: 1rem;
265
+ position: relative;
266
+ z-index: 3;
267
  }
268
 
269
  .hero p {
270
  font-size: 1.2rem;
271
  margin-bottom: 2rem;
272
+ position: relative;
273
+ z-index: 3;
274
  }
275
 
276
  .btn {
 
280
  padding: 1rem 2rem;
281
  text-decoration: none;
282
  border-radius: 5px;
283
+ transition: all 0.3s;
284
+ position: relative;
285
+ z-index: 3;
286
+ border: none;
287
+ cursor: pointer;
288
  }
289
 
290
  .btn:hover {
291
  background-color: #c0392b;
292
+ transform: translateY(-2px);
293
+ box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
294
  }
295
  """
296
 
 
300
  padding: 4rem 2rem;
301
  max-width: 1200px;
302
  margin: 0 auto;
303
+ position: relative;
304
+ z-index: 10;
305
  }
306
 
307
  .cards-grid {
 
309
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
310
  gap: 2rem;
311
  margin-top: 2rem;
312
+ position: relative;
313
+ z-index: 11;
314
  }
315
 
316
  .card {
 
318
  border-radius: 10px;
319
  padding: 2rem;
320
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
321
+ transition: all 0.3s;
322
+ position: relative;
323
+ z-index: 12;
324
+ overflow: hidden;
325
+ }
326
+
327
+ .card::before {
328
+ content: '';
329
+ position: absolute;
330
+ top: 0;
331
+ left: 0;
332
+ right: 0;
333
+ bottom: 0;
334
+ background: linear-gradient(45deg, transparent, rgba(52, 152, 219, 0.1), transparent);
335
+ opacity: 0;
336
+ transition: opacity 0.3s;
337
+ z-index: -1;
338
  }
339
 
340
  .card:hover {
341
  transform: translateY(-5px);
342
+ box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
343
+ z-index: 13;
344
+ }
345
+
346
+ .card:hover::before {
347
+ opacity: 1;
348
+ }
349
+
350
+ .card h3 {
351
+ position: relative;
352
+ z-index: 2;
353
+ margin-bottom: 1rem;
354
+ }
355
+
356
+ .card p {
357
+ position: relative;
358
+ z-index: 2;
359
  }
360
  """
361
 
 
364
  .form-section {
365
  padding: 4rem 2rem;
366
  background-color: #f8f9fa;
367
+ position: relative;
368
+ z-index: 5;
369
  }
370
 
371
  .form-container {
 
375
  padding: 2rem;
376
  border-radius: 10px;
377
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
378
+ position: relative;
379
+ z-index: 6;
380
  }
381
 
382
  .form-group {
383
  margin-bottom: 1.5rem;
384
+ position: relative;
385
+ z-index: 7;
386
  }
387
 
388
  .form-group label {
389
  display: block;
390
  margin-bottom: 0.5rem;
391
  font-weight: bold;
392
+ position: relative;
393
+ z-index: 8;
394
  }
395
 
396
  .form-group input,
 
400
  border: 1px solid #ddd;
401
  border-radius: 5px;
402
  font-size: 1rem;
403
+ position: relative;
404
+ z-index: 8;
405
+ background: white;
406
+ transition: all 0.3s;
407
  }
408
 
409
  .form-group input:focus,
410
  .form-group textarea:focus {
411
  outline: none;
412
  border-color: #3498db;
413
+ box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
414
+ z-index: 9;
415
+ }
416
+
417
+ .form-group input:focus + .focus-indicator,
418
+ .form-group textarea:focus + .focus-indicator {
419
+ opacity: 1;
420
+ transform: scaleX(1);
421
  }
422
  """
423
 
 
429
  text-align: center;
430
  padding: 2rem 0;
431
  margin-top: 4rem;
432
+ position: relative;
433
+ z-index: 100;
434
+ }
435
+
436
+ .footer p {
437
+ position: relative;
438
+ z-index: 101;
439
  }
440
  """
441
 
442
+ # Add animations if requested with proper z-index
443
  if components['has_animation']:
444
  css += """
445
  @keyframes fadeInUp {
 
453
  }
454
  }
455
 
456
+ @keyframes slideInFromLeft {
457
+ from {
458
+ opacity: 0;
459
+ transform: translateX(-50px);
460
+ }
461
+ to {
462
+ opacity: 1;
463
+ transform: translateX(0);
464
+ }
465
+ }
466
+
467
  .animate-on-scroll {
468
+ animation: fadeInUp 0.6s ease-out forwards;
469
+ }
470
+
471
+ .animate-slide {
472
+ animation: slideInFromLeft 0.8s ease-out forwards;
473
+ }
474
+
475
+ /* Ensure animated elements don't interfere with z-index */
476
+ .animate-on-scroll,
477
+ .animate-slide {
478
+ position: relative;
479
+ z-index: auto;
480
  }
481
  """
482
 
483
+ # Add modal and overlay styles with high z-index
484
+ css += """
485
+ /* Modal and overlay z-index management */
486
+ .modal-overlay {
487
+ position: fixed;
488
+ top: 0;
489
+ left: 0;
490
+ right: 0;
491
+ bottom: 0;
492
+ background: rgba(0, 0, 0, 0.5);
493
+ z-index: 9998;
494
+ display: none;
495
+ }
496
+
497
+ .modal {
498
+ position: fixed;
499
+ top: 50%;
500
+ left: 50%;
501
+ transform: translate(-50%, -50%);
502
+ background: white;
503
+ padding: 2rem;
504
+ border-radius: 10px;
505
+ z-index: 9999;
506
+ max-width: 90vw;
507
+ max-height: 90vh;
508
+ overflow: auto;
509
+ }
510
+
511
+ /* Dropdown menus */
512
+ .dropdown {
513
+ position: relative;
514
+ z-index: 200;
515
+ }
516
+
517
+ .dropdown-menu {
518
+ position: absolute;
519
+ top: 100%;
520
+ left: 0;
521
+ background: white;
522
+ border: 1px solid #ddd;
523
+ border-radius: 5px;
524
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
525
+ z-index: 201;
526
+ min-width: 200px;
527
+ display: none;
528
+ }
529
+
530
+ .dropdown:hover .dropdown-menu {
531
+ display: block;
532
+ }
533
+
534
+ /* Tooltips */
535
+ .tooltip {
536
+ position: relative;
537
+ z-index: 300;
538
+ }
539
+
540
+ .tooltip::after {
541
+ content: attr(data-tooltip);
542
+ position: absolute;
543
+ bottom: 125%;
544
+ left: 50%;
545
+ transform: translateX(-50%);
546
+ background: #333;
547
+ color: white;
548
+ padding: 0.5rem;
549
+ border-radius: 4px;
550
+ font-size: 0.875rem;
551
+ white-space: nowrap;
552
+ opacity: 0;
553
+ pointer-events: none;
554
+ transition: opacity 0.3s;
555
+ z-index: 301;
556
+ }
557
+
558
+ .tooltip:hover::after {
559
+ opacity: 1;
560
+ }
561
+
562
+ /* Responsive z-index adjustments */
563
+ @media (max-width: 768px) {
564
+ .header {
565
+ z-index: 1100;
566
+ }
567
+
568
+ .nav {
569
+ z-index: 1101;
570
+ }
571
+
572
+ .mobile-menu {
573
+ position: fixed;
574
+ top: 0;
575
+ left: 0;
576
+ right: 0;
577
+ bottom: 0;
578
+ background: rgba(44, 62, 80, 0.95);
579
+ z-index: 1200;
580
+ display: none;
581
+ }
582
+
583
+ .mobile-menu.active {
584
+ display: flex;
585
+ flex-direction: column;
586
+ justify-content: center;
587
+ align-items: center;
588
+ }
589
+ }
590
+ """
591
+
592
+ # Fix z-index conflicts and return optimized CSS
593
+ return fix_zindex_conflicts(css)
594
 
595
  def generate_html_structure(prompt: str, components: dict) -> str:
596
  """Generate HTML structure based on components."""