可扩展列表的响应式设计可以通过以下几个步骤来实现:
<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);
});
通过以上方法,你可以实现一个可扩展的响应式列表设计。请根据实际需求调整代码和样式。