javascript - Angular 8应用程序,使用片段时与标题重叠
问题描述
我有一个链接,通过单击链接,我想滚动到页面底部的片段。当我单击链接时,该片段正在工作,但该片段被标题组件重叠。请看图片:
以下是我的 app.component.html 中的代码:
<div class="layout-wrapper">
<header>
<app-header></app-header>
</header>
<main id="layout-content" [ngClass]="{ active: menuActive }">
<div>
<router-outlet></router-outlet>
</div>
</main>
<footer>
<app-footer></app-footer>
</footer>
</div>
在主标签上,我有一个 CSS 样式,顶部有填充
#layout-content {
margin-left: 0;
padding-top: 120px;
margin-right: 0;
}
但是,当我单击片段链接时,它会将其带到顶部并与标题重叠。
我的链接和片段的组件代码:
<a [routerLink]="['/proposal']" fragment="dcn">{{ dcn }}</a>
<section id="dcn">
Some other html here
</section>
为什么不应用填充?如何应用填充?
解决方案
在想出一个使用 css 的解决方案之后,我查看了 angular routing api 并找到了解决方案,它正在使用
scrollOffset: [0, 135]
在我的 app-routing.module.ts 文件中的路由选项中。现在,片段在 135px 之后开始,这是我的标题的长度。
推荐阅读
- html - 在带有过渡的链接悬停时显示图像
- reactjs - 无法使用 firebase 在本地运行 mocha 测试
- graphql - HTML 结构的 GraphQL 自定义标量类型
- python - Flask 禁用 JSON 响应转义
- python - 如何在特定行上旋转熊猫数据框
- apache-kafka - Kafka Mirror Maker:同步 __consumer_offsets 主题重复项
- php - 如何在三个表上运行两个查询并在一个表中输出一列的结果
- python - 我的列表正在更改,我不知道为什么
- java - 向 arrayList 添加标记会导致应用程序崩溃
- python - 如何在python中概率性地填充列表?