可擴展列表的響應式設計可以通過以下幾個步驟來實現:
<ul>
)和列表項(<li>
)標簽。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive List</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<ul class="responsive-list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<!-- Add more list items as needed -->
</ul>
</body>
</html>
/* styles.css */
/* Remove default list styles */
.responsive-list {
list-style-type: none;
margin: 0;
padding: 0;
}
/* Set list item styles */
.responsive-list li {
padding: 10px;
border-bottom: 1px solid #ccc;
}
/* Responsive design */
@media (max-width: 600px) {
.responsive-list li {
font-size: 14px;
padding: 8px;
}
}
@media (min-width: 601px) and (max-width: 1024px) {
.responsive-list li {
font-size: 16px;
padding: 10px;
}
}
@media (min-width: 1025px) {
.responsive-list li {
font-size: 18px;
padding: 12px;
}
}
// app.js
document.addEventListener('DOMContentLoaded', function () {
const list = document.querySelector('.responsive-list');
// Add a new list item
function addItem() {
const newItem = document.createElement('li');
newItem.textContent = 'New Item';
list.appendChild(newItem);
}
// Remove the last list item
function removeItem() {
if (list.lastElementChild) {
list.removeChild(list.lastElementChild);
}
}
// Add event listeners to buttons (if any)
document.querySelector('#add-item').addEventListener('click', addItem);
document.querySelector('#remove-item').addEventListener('click', removeItem);
});
通過以上方法,你可以實現一個可擴展的響應式列表設計。請根據實際需求調整代碼和樣式。