[英]Making title sticky on top of sticky div (tocbot)
I'm building a Table of Contents section on my website using tocbot , but I'm having an issue making the Title I added above it stick to the table of contents when I scroll.我正在使用tocbot在我的网站上构建一个目录部分,但是我在滚动时遇到问题,使我在其上方添加的标题坚持到目录中。
Here's what I've got so far:这是我到目前为止所得到的:
<div id="desktop-toc" class="tiktoc">
<p class="toc-title">Content Navigation</p>
<aside class="toc-container js-sticky">
<div class="toc"></div>
</aside>
</div>
CSS CSS
/* Start Table of Contents styling */
.toc-container {
display: -webkit-box;
display: flex;
-webkit-box-align: right;
align-items: left;
}
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px),
only screen and (min-width: 600px)
/* Medium devices (landscape tablets, 768px and up) */
@media(min-width: 768px) and (orientation:landscape),
only screen and (max-width: 768px) {
.tiktoc {
display: none;
}
.toc-container {
display: none;
}
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px)
{
.tiktoc {
position: absolute;
top: 175px;
left: 1150px;
bottom: 0;
width: 350px;
margin-bottom: 0;
}
.toc {
font-size: 16px;
line-height: 1.6em;
padding: 20px;
min-width: 250px;
max-width: 300px;
background-color: #212121;
color: #fff;
}
.toc-title {
font-size: 22px;
font-weight: bolder;
padding-bottom: 10px;
position: sticky;
text-align: left;
color: var(--primary-foreground-color);
}
.is-active-link::before {
background-color: #FE0152;
}
}
I've tried placing the title inside the div with the "js-sticky" class, but it formats them inline, instead of on top of the TOC section.我尝试将标题放在带有“js-sticky”class 的 div 中,但它内联格式化它们,而不是在 TOC 部分的顶部。
It looks like adding the title inside the aside
should do the trick:看起来在aside
添加标题应该可以解决问题:
<div id="desktop-toc" class="tiktoc">
<aside class="toc-container js-sticky">
<p class="toc-title">Content Navigation</p>
<div class="toc"></div>
</aside>
</div>
Figured this out, for anybody who has a similar issue in future.想通了这一点,对于将来有类似问题的任何人。
Using tocbot, class js-sticky
was setting top: 150px;
使用 tocbot,class js-sticky
设置为top: 150px;
and hiding the title element beneath the Table of Contents.并将标题元素隐藏在目录下方。 I overrode this setting by adding top: 110px;
我通过添加top: 110px;
覆盖了这个设置。 to the title class toc-title
I had created and set it as !important
.到我创建的标题 class toc-title
并将其设置为!important
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.