首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >html书签链接某些文本不出现

html书签链接某些文本不出现
EN

Stack Overflow用户
提问于 2022-03-30 14:01:08
回答 2查看 51关注 0票数 1

我创建了一个指向同一个页面的链接(Bookmark)。但我现在面临一个问题。当我从侧边栏单击链接上的链接时,它工作正常,但标题或某些部分在显示中没有正确显示。

当我单击链接时,标题或某个部分将被隐藏在标题中。

但我想要完整的部分被展示成这样-

我该如何解决这个问题?

代码语言:javascript
复制
header{
width: 100%;
height: 50px;
border-bottom: 1px solid #333;
background-color: #fff;
z-index: 5;
top: 0;
position: fixed;
}
nav{
width: 20%;
height: 100%;
top: 0;
left: 0;
position: fixed;
border-right: 1px solid #333;
}
article{
padding-top: 60px;
margin-left: 20%;
width: 60%;
}
aside{
width: 20%;
right: 0;
top: 0;
position: fixed;
border-left: 1px solid #333;
height: 100%;
padding-top: 60px;
}
代码语言:javascript
复制
<header></header>
<nav></nav>

<article>
<a name="hyper-1"></a>
<h1>Hyper 1</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>

<a name="hyper-2"></a>
<h1>Hyper 2</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>

<a name="hyper-3"></a>
<h1>Hyper 3</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</article>

<aside>
IN THIS CONTENT:
<a href="#hyper-1">Hyper-1</a><br/>
<a href="#hyper-2">Hyper-2</a><br/>
<a href="#hyper-3">Hyper-3</a><br/>
</aside>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-03-30 14:10:39

这个问题是由于元素是空的。它们没有一致性,滚动到此元素时不要在div顶部按下

要解决这个问题,一个想法可以是在<a>之后有一个隐藏的after元素,当滚动到这个锚点时,按预期按下

代码语言:javascript
复制
article a::after {
  content: ' ';
  padding: 12px;
}

代码语言:javascript
复制
header {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #333;
  background-color: #fff;
  z-index: 5;
  top: 0;
  position: fixed;
}

nav {
  width: 20%;
  height: 100%;
  top: 0;
  left: 0;
  position: fixed;
  border-right: 1px solid #333;
}

article {
  padding-top: 60px;
  margin-left: 20%;
  width: 60%;
}

article a::after {
  content: ' ';
  padding: 12px;
}

aside {
  width: 20%;
  right: 0;
  top: 0;
  position: fixed;
  border-left: 1px solid #333;
  height: 100%;
  padding-top: 60px;
}
代码语言:javascript
复制
<header></header>
<nav></nav>

<article>
  <a name="hyper-1"></a>
  <h1>Hyper 1</h1>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </p>

  <a name="hyper-2"></a>
  <h1>Hyper 2</h1>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </p>

  <a name="hyper-3"></a>
  <h1>Hyper 3</h1>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </p>
</article>

<aside>
  IN THIS CONTENT:
  <a href="#hyper-1">Hyper-1</a><br/>
  <a href="#hyper-2">Hyper-2</a><br/>
  <a href="#hyper-3">Hyper-3</a><br/>
</aside>

票数 1
EN

Stack Overflow用户

发布于 2022-03-30 14:07:47

如果我得到的正确,你需要滚动到页面顶部任何时候,它被加载..。因为它可以从来自同一个页面的链接中加载。

一种解决方案是在页面准备就绪后立即在页面顶部滚动:

代码语言:javascript
复制
$(document).ready(function(){
    $(this).scrollTop(0);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71678650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档