[英]How to make table of contents in sidebar using CSS?
I would like to make a webpage with a sidebar table of contents (TOC) like this:我想制作一个带有侧边栏目录(TOC)的网页,如下所示:
https://bookdown.org/yihui/bookdown/html.html https://bookdown.org/yihui/bookdown/html.html
The TOC is currently at the top of the HTML page this way: TOC 目前以这种方式位于 HTML 页面的顶部:
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul style="list-style-type:none">
...
<li><a href="#orgbdecee3">Topic 1</a></li>
</ul>
</div>
How can I create a CSS file so that such a TOC appears as a sidebar?如何创建一个 CSS 文件,以便这样的 TOC 显示为侧边栏?
You can use position absolute
and fixed
to solve our problem.您可以使用
absolute
位置和fixed
位置来解决我们的问题。
.grid{ position:relative; width:100%; height:100vh; color:#fff; } .one{ position:fixed; top:0; left:0; bottom:0; width:25%; background:#333; } .two{ position:absolute; top:0; left:25%; bottom:0; width:75%; background:#999; height:120%; }
<div class="grid"> <div class="one">aaa</div> <div class="two">aaa</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.