gpt4 book ai didi

html - 单击固定标题中的相应链接时如何获取该部分

转载 作者:行者123 更新时间:2023-11-27 23:26:50 26 4
gpt4 key购买 nike

场景:当我点击固定标题中的 title1 链接时,它应该显示 title1 部分​​,当我点击 title2 链接时,它应该像那样在顶部显示 title 2 部分..但这里它显示在顶部页面但在页眉后面,所以它不可见

我附上了我试过的代码,请帮助解决这个问题

.menu {
height: 165px;
position: fixed;
background-color: lightgrey;
margin-top: -113px;
width: 1090px;
}

#menu-center ul {
margin:35px 0 0px 115px
}
#menu-center ul li {
list-style: none;
margin: 0 30px 0 0;
display: inline;
}
.Avatar1{
background: #ED7D31;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar2{
background: #A5A5A5;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar3{
background: #FFC000;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar4{
background: #5b9bd5;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar5{
background: #70AD47;
border-radius:50%;
display:inline-block;
padding:10px;
}
div.item {
vertical-align: top;
display: inline-block;
text-align: center;
width: 120px;
}
.caption {
display: block;
color:#ffffff;
}

#Title1 {

height: 100%;
width: 100%;

padding-top: 165px;


}
#Title2 {
height: 100%;
width: 100%;
padding-top: 25px;
}
#Title3{
height: 100%;
width: 100%;
padding-top: 25px;
}

#Title4 {
height: 100%;
width: 100%;
padding-top: 25px;
}
#Title5 {
height: 100%;
width: 100%;
padding-top: 280px;
}
.vertical {
border-left: 190px solid #5786c5;

margin-left:900px;
margin-top: -1620px;
height: 1620px;
}
.items-01{
margin-right: 253px;
font-size: 16px;
line-height:1.8;
}
<body>
<table width="1094px" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<div>
<h2 style="
font-size: 28px;
text-align: center;
margin-left: -150px;">Heading</h2>
<div class="m1 menu">
<div id="menu-center">
<ul>
<li><a class="nav-link" href="#Title1"><div class="item"><img src="picture.png" class="Avatar1" width="50" height="50" > <span class="caption">Title1</span></div></a>

</li>
<li><a class="nav-link" href="#Title2"><div class="item"><img src="picture.png" class="Avatar2" width="50" height="50" > <span class="caption">Title2​</span></div></a>

</li>
<li><a class="nav-link" href="#Title3"><div class="item"><img src="picture.png" class="Avatar3" width="50" height="50" > <span class="caption">Title3</span></div></a>

</li>
<li><a class="nav-link" href="#Title4"><div class="item"><img src="picture.png" class="Avatar4" width="50" height="50" > <span class="caption">Title4</span></div></a>

</li>
</li>
<li><a class="nav-link" href="#objective"><div class="item"><img src="picture.png" class="Avatar5" width="50" height="50" > <span class="caption">Title5</span></div></a>

</li>
</ul>
</div>
</div>
<div style="margin-top:0px;">
<div class="content" id="Title1">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title1
</h1>
<ul>
<li class="items-01">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
</li>
</ul>
</div>
<div class="content" id="Title2" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title2
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text of the printing
</li>
</ul>
</div>
<div class="content" id="Title3" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title3
</h1>
<ul>
<li class="items-01">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.
</li>
</ul>
</div>
<div class="content" id="Title4" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title4
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
</ul>
</div>
<div class="content" id="Title5" style="margin-top:0px;" >
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title5
</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.<br/><br/>
when an unknown printer took a galley of type and scrambled it to make a type specimen book</p>



<ul>
<li class="items-01">Lorem Ipsum is simply dummy text </li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>


</ul>

</div>

</div>
</div>
</td>
</tr>
</table>
</body>

最佳答案

可以使用javascript和jquery库来实现。

  • 将 jquery 库导入您的代码。
  • 在脚本标签内使用下面的代码。
$('#menu-center ul').find('a').click(function(e){

e.preventDefault();

var menuHeight = $('.menu').height();
var $href = $(this).attr('href');
var $anchor = $($href).offset(); // Get position of section.

//Scroll particular section to top with adjusting menu height.
window.scrollTo($anchor.left,$anchor.top- menuHeight);

return false;

});

关于html - 单击固定标题中的相应链接时如何获取该部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57735664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com