Gdzie wykorzystać ten przykład?
Panele, listy, cenniki i narzędzia pomocnicze. Wariant „Lista z filtrem i stronicowaniem” możesz dopasować do kolorów i treści swojej strony.
Jak działa ten efekt?
Operacje na tablicach i liczbach aktualizują podsumowania i widok danych w przeglądarce.
Jak dodać go na stronę?
- Otwórz przykład w edytorze i podmień tekst oraz kolory.
- HTML wstaw w miejscu, w którym ma pojawić się element.
- CSS przenieś do arkusza stylów swojej strony. Reguły
body z podglądu dopasuj do własnego układu. - JavaScript uruchom po załadowaniu elementów HTML, na przykład przed zamknięciem
</body>. - Sprawdź działanie na telefonie, klawiaturą i z własną treścią.
Na co zwrócić uwagę?
W produkcji sprawdzaj dane wejściowe i zakres liczb. Przykładowe ceny i stawki nie stanowią aktualnego cennika.
Co możesz zmienić w konfiguratorze?
Nagłówek, Kolor akcentu, Zaokrąglenie. W edytorze kodu możesz dodatkowo zmienić całą strukturę i zachowanie przykładu.
Gotowy kod: Lista z filtrem i stronicowaniem
HTML
<section class="lab"><h2>Lista z filtrem i stronicowaniem</h2><input class="page-search" type="search" placeholder="Szukaj projektu" aria-label="Szukaj projektu"><ul class="page-list"></ul><button class="page-prev">Poprzednia</button> <span class="page-number"></span> <button class="page-next">Następna</button></section>
CSS
*{box-sizing:border-box}body{margin:0;padding:35px 24px;background:#f4f5ef;color:#293322;font:15px/1.7 Arial,sans-serif;min-height:100vh;display:grid;place-items:center}button,input{font:inherit}button,a{touch-action:manipulation}button{cursor:pointer}button:focus-visible,a:focus-visible,summary:focus-visible{outline:3px solid #738858;outline-offset:4px}h2,h3,p{margin-top:0}[hidden]{display:none!important}@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.lab{max-width:800px;margin:25px auto;padding:25px;border:1px solid #d4dec9;border-radius:14px;background:#fff;color:#273724;font:15px/1.6 system-ui,sans-serif;overflow-wrap:anywhere}.lab *{box-sizing:border-box}.lab h2{font-size:23px;margin:0 0 25px;line-height:1.3}.lab h3{line-height:1.3}.lab label{display:block;margin:10px 0}.lab input:not([type=checkbox]):not([type=radio]),.lab select,.lab textarea{font:inherit;padding:9px;border:1px solid #bac9ad;border-radius:6px;max-width:100%;background:#fff;color:#273724}.lab input[type=range]{width:100%;accent-color:#6f8e58}.lab input[type=color]{height:45px;width:70px}.lab input[type=checkbox]{accent-color:#6f8e58;margin-right:8px}.lab textarea{width:100%}.lab button{font:inherit;font-weight:600;border:0;border-radius:14px;background:#6f8e58;color:#fff;padding:10px 16px;cursor:pointer}.lab button:disabled{opacity:.45;cursor:default}.lab :focus-visible{outline:3px solid #315f8b;outline-offset:3px}.lab pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#f0f4e9;padding:15px;font:12px/1.6 monospace}.lab table{border-collapse:collapse;width:100%}.lab th,.lab td{padding:10px;text-align:left;border-bottom:1px solid #d9e3ce}.lab progress{accent-color:#6f8e58}.lab .lab-hint{font-size:11px;color:#687861;border-top:1px solid #dbe3d0;padding-top:16px;margin-top:25px}.lab [hidden]{display:none!important}@media(max-width:480px){.lab{padding:16px;margin:10px auto}.lab h2{font-size:20px}.lab table{font-size:12px}.lab th,.lab td{padding:7px}}@media(prefers-reduced-motion:reduce){.lab *{animation:none!important;transition:none!important}}
.page-list{list-style:none;padding:0;min-height:180px}.page-list li{padding:12px;border-bottom:1px solid #d3dec8}.page-number{margin:0 12px}
JavaScript
const data=Array.from({length:18},(_,i)=>'Projekt '+String(i+1).padStart(2,'0')),search=document.querySelector('.page-search');let page=0;function render(){const filtered=data.filter(text=>text.toLowerCase().includes(search.value.toLowerCase())),pages=Math.max(1,Math.ceil(filtered.length/4));page=Math.min(page,pages-1);const list=document.querySelector('.page-list');list.replaceChildren();filtered.slice(page*4,page*4+4).forEach(text=>{const li=document.createElement('li');li.textContent=text;list.append(li)});if(!filtered.length)list.textContent='Brak wyników.';document.querySelector('.page-number').textContent=(page+1)+' / '+pages;document.querySelector('.page-prev').disabled=page===0;document.querySelector('.page-next').disabled=page===pages-1}search.oninput=()=>{page=0;render()};document.querySelector('.page-prev').onclick=()=>{page--;render()};document.querySelector('.page-next').onclick=()=>{page++;render()};render();