CSS(层叠样式表)是一种用于描述HTML或XML(包括SVG、MathML等各种XML方言)文档样式的样式表语言。通过CSS,可以控制网页的布局和外观,包括颜色、字体、布局等。
以下是一个简单的固定侧边栏的示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>侧边栏示例</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
.sidebar {
height: 100%;
width: 200px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
}
.sidebar a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
.sidebar a:hover {
color: #f1f1f1;
}
.main {
margin-left: 200px; /* Same as the width of the sidebar */
padding: 20px;
}
</style>
</head>
<body>
<div class="sidebar">
<a href="#home">Home</a>
<a href="#services">Services</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
<div class="main">
<h2>Main Content</h2>
<p>This is the main content area.</p>
</div>
</body>
</html>
position: fixed;
属性。overflow-x: hidden;
隐藏水平滚动条。通过以上方法,可以有效地设置和管理侧边栏的样式和布局。
领取专属 10元无门槛券
手把手带您无忧上云