请写一个网页左边显示目录栏目录二字左右居中显示三个章节且章节前不带点目录栏上下占满
以下是一个简单的示例网页,满足您的要求:
<!DOCTYPE html>
<html>
<head>
<title>目录栏网页</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
}
.sidebar {
width: 200px;
height: 100vh;
background-color: #f3f3f3;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.sidebar h2 {
margin: 0;
padding: 10px;
text-align: center;
}
.content {
flex-grow: 1;
height: 100vh;
padding: 20px;
background-color: #fff;
}
.content h1 {
margin-top: 0;
}
</style>
</head>
<body>
<div class="sidebar">
<h2>目录</h2>
<ul>
<li><a href="#chapter1">章节一</a></li>
<li><a href="#chapter2">章节二</a></li>
<li><a href="#chapter3">章节三</a></li>
</ul>
</div>
<div class="content">
<h1 id="chapter1">章节一</h1>
<p>这是章节一的内容。</p>
<h1 id="chapter2">章节二</h1>
<p>这是章节二的内容。</p>
<h1 id="chapter3">章节三</h1>
<p>这是章节三的内容。</p>
</div>
</body>
</html>
在这个示例中,我们使用了Flex布局来实现左边的目录栏和右边的内容区域。目录栏使用了一个侧边栏类名为 .sidebar,通过设置宽度、背景颜色、垂直居中和水平居中的方式来使其上下占满,并且目录标题 "目录" 使用了居中样式。
内容区域使用了 .content 类名,并设置 flex-grow: 1,使其占满剩余的空间。章节标题使用了 h1 标签,并通过设置 id 属性来实现目录链接的跳转。
整个网页在浏览器中打开后,左边是目录栏,右边是内容区域,目录栏上下占满屏幕,目录栏中显示了三个章节,并且章节前不带点
AI 优化版
原文地址:https://www.cveoy.top/t/topic/iMPw 著作权归作者所有。请勿转载和采集!