我有一个链接到网页各个部分的菜单,我希望链接转到标题,但它会转到该部分的末尾,这会让人觉得它会转到下面的部分。我尝试了几种方法,这是第一种方式;
<div class="sidebar" style="margin-top: -315px;">
<div class="list-group">
<a href="Index.aspx#WhatIsIt" class="list-group-item active">What is it?</a>
<a href="Index.aspx#Why" class="list-group-item">Why Evercam?</a>
<a href="Index.aspx#API" class="list-group-item">API</a>
<a href="Index.aspx#Pricing" class="list-group-item">Pricing</a>
<a href="MarketPlace.aspx" class="list-group-item">MarketPlace</a>
</div>
</div>
<section id="WhatIsIt">
<div class="row featurette">
<div class="col-md-4">
<i class="icon-camera-retro icon-large"></i>
</div>
<div class="col-md-8" style="margin-left: -55px">
<h2 class="featurette-heading smalltopmargin">What is Evercam?<span class="text-muted">An ideal camera.</span></h2>
<p class="lead">
Evercam makes it easy to interact with IP Cameras. Evercam abstracts the complexity of any IP-based video device, and exposes all its available functionality to you
through a consistent and beautiful <a href="/Develop.aspx">API</a>.
</p>
</div>
</div>
</section>
这是第二种方式;
<div class="terms">
<h3>Index</h3>
<h5><a href="Termsandconditions.aspx#yourrights">Your rights</a></h5>
<h5><a href="Termsandconditions.aspx#cookies">Cookies</a></h5>
<h5><a href="Termsandconditions.aspx#changes">Changes</a></h5>
<h5><a href="Termsandconditions.aspx#ordering">Ordering</a></h5>
<h5><a href="Termsandconditions.aspx#license">License</a></h5>
<h5><a href="Termsandconditions.aspx#siteusage">Site usage</a></h5>
<h5><a href="Termsandconditions.aspx#ownership">Ownership of information</a></h5>
<h5><a href="Termsandconditions.aspx#accuracyofinfo">Accuracy of information</a></h5>
<h5><a href="Termsandconditions.aspx#pricing">Pricing liability</a></h5>
</div>
<h3><a name="yourrights"></a>Your rights</h3>
关于如何解决这个问题的任何想法?
答案 0 :(得分:1)
您可以使用以下内容:&lt; a name =“anchorName”href =“#anchorName2&gt;&lt; / a&gt;
<a name="first" href="#forth" class="tall red"></a>
<a name="second" class="tall blue"></a>
<a name="third" class="tall green"></a>
<a name="forth" class="tall purple"></a>
然后锚将跳转到任何&lt; a&gt;标签有这个名字。
答案 1 :(得分:1)
id属性可用于在任何元素的开始标记处创建锚点(包括A元素)。
参考:http://www.w3.org/TR/html4/struct/links.html#h-12.2.3
所以你的解决方案似乎正确。我认为可能还有其他事情发生(浏览器无法滚动到您想要的位置,边距/填充错误)这会弄乱滚动。
答案 2 :(得分:0)
这个“容器类”是否会影响链接?
.container {
padding-right: 225px;
padding-left: 30px;
margin-right: auto;
margin-left: auto;
}