<!DOCTYPE html> <head> <meta charset="UTF-8"> <meta name="viewport"…
- Usercode
<script src="script.js"></script>.inner-div { position: absolute; width: 100px; height: 100px; background-color: rgb(255, 0, 174); display: flex; align-items: center; justify-content: center; border: 1px solid black; }
#controls button { padding: 10px 20px; margin-right: 10px; cursor: pointer; } class Controller { constructor(presenter) { this.presenter = presenter; }
codehandleEvent(element) { this.presenter.setLayout(element); }}
class Presenter { constructor(containerId) { this.container = document.getElementById(containerId); this.divs = this.container.querySelectorAll('.inner-div'); }
codesetLayout(layoutType) { // Wyczyść wszystkie style dla divs this.divs.forEach(div => { div.style.removeProperty('left'); div.style.removeProperty('top'); div.style.removeProperty('right'); div.style.removeProperty('bottom'); div.textContent = ''; }); // Stosuj nowe style w zależności od układu switch (layoutType) { case 'A': // Układ X this.divs[0].style.left = '0'; this.divs[0].style.top = '0'; this.divs[0].textContent = 'Jan'; this.divs[1].style.left = '45%'; this.divs[1].style.top = '45%'; this.divs[1].textContent = 'Kowalski'; this.divs[2].style.right = '0'; this.divs[2].style.bottom = '0'; break; case 'B': // Układ Y this.divs.forEach((div, index) => { div.style.left = `${index * 33.3}%`; div.style.top = '45%'; }); this.divs[0].textContent = 'Jan'; this.divs[1].textContent = 'Kowalski'; break; case 'C': // Układ Z this.divs[0].style.left = '0'; this.divs[0].style.top = '0'; this.divs[1].style.left = '12%'; this.divs[1].style.top = '0'; this.divs[2].style.right = '0'; this.divs[2].style.bottom = '0'; this.divs[2].textContent = 'Jan'; this.divs[3].style.right = '12%'; this.divs[3].style.bottom = '0'; this.divs[3].textContent = 'Kowalski'; break; } } - Assistant
W opisanej sytuacji wydaje się, że problemem jest jeden z elementów o klasie
inner-div, który jest stale widoczny mimo, że nie powinien być na początku. Możliwe, że jest to spowodowane jakimś błędem w kodzie CSS lub JavaScript. Sprawdźmy to krok po kroku.-
Sprawdzenie CSS: Pierwszą rzeczą, którą warto zrobić, jest upewnić się, że styl CSS dla klasy rzeczywiście ustawia na dla wszystkich -ów tego typu na starcie, aby były one domyślnie niewidoczne. Sprawdź, czy następujący styl jest poprawnie załadowany w pliku :
-
- User
napisz caly kod jak ma wygladac zebym mogl sobie go skopiowac
- Assistant
- User
okej teraz musisz zrobic zeby w case B byly 3 kwadraty bo sa 4
- Assistant
- User
oki teraz chce zeby case byl bardziej wysrodkowany bo teraz jest przesuniety do lewej strony
- Assistant