侧边栏可以隐藏的,可以展开的
时间: 2024-02-25 07:51:54 浏览: 141
显示/隐藏侧边栏
好的,我了解了您的需求。以下是一个简单的网页设计,包括一个可以隐藏和展开的侧边栏。
```HTML
<!DOCTYPE html>
<html>
<head>
<title>可展开侧边栏</title>
<style>
body {
margin: 0;
padding: 0;
}
#sidebar {
position: fixed;
top: 0;
left: -200px;
width: 200px;
height: 100vh;
background-color: #333;
color: #fff;
transition: all 0.3s ease-in-out;
z-index: 999;
}
#sidebar.open {
left: 0;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
#sidebar ul {
list-style: none;
padding: 0;
margin: 0;
}
#sidebar ul li {
padding: 10px;
border-bottom: 1px solid #555;
}
#sidebar ul li:hover {
background-color: #555;
cursor: pointer;
}
#main {
padding: 20px;
margin-left: 200px;
}
#toggle-sidebar {
position: fixed;
top: 10px;
left: 10px;
width: 30px;
height: 30px;
background-color: #333;
color: #fff;
border: none;
border-radius: 50%;
font-size: 20px;
text-align: center;
line-height: 1.5;
cursor: pointer;
z-index: 999;
}
</style>
</head>
<body>
<div id="sidebar">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
</ul>
</div>
<div id="main">
<button id="toggle-sidebar">☰</button>
<h1>Main Content</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut dolor ut ipsum tristique feugiat. Nullam nec iaculis urna. Sed sed mauris a felis rhoncus euismod ut vel odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent tincidunt lacus ac urna consequat ullamcorper. Nam euismod augue at enim malesuada, quis placerat augue laoreet. Donec convallis sapien ut leo fringilla, vel bibendum sapien pharetra. Donec pretium, orci vel bibendum sodales, nulla sapien venenatis velit, eget faucibus justo magna sed justo. Quisque tincidunt mauris nec diam aliquam, quis pulvinar quam ultrices. Vestibulum lacinia iaculis ex, in vehicula mauris tincidunt eget. Vivamus euismod at metus in bibendum. Donec id imperdiet nulla.</p>
</div>
<script>
document.getElementById('toggle-sidebar').addEventListener('click', function() {
document.getElementById('sidebar').classList.toggle('open');
});
</script>
</body>
</html>
```
这是一个简单的 HTML 页面,包括一个侧边栏和主内容区域。侧边栏可以通过点击按钮展开或隐藏。请将这些代码复制到一个 HTML 文件中,然后在浏览器中打开该文件,即可查看效果。
阅读全文