可擴(kuò)展列表的響應(yīng)式設(shè)計(jì)可以通過以下幾個(gè)步驟來實(shí)現(xiàn):
<ul>
)和列表項(xiàng)(<li>
)標(biāo)簽。<!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);
});
通過以上方法,你可以實(shí)現(xiàn)一個(gè)可擴(kuò)展的響應(yīng)式列表設(shè)計(jì)。請(qǐng)根據(jù)實(shí)際需求調(diào)整代碼和樣式。