Вопрос

I have a menu that links to sections of a webpage, I want the link to go to the header but it goes to the end of the section which gives the impression that it is going to the section below it. I have tried it a couple of ways, here is the first way;

<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>

Here is the second way;

<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>

Any ideas on how to solve this?

Это было полезно?

Решение

The id attribute may be used to create an anchor at the start tag of any element (including the A element).

Ref: http://www.w3.org/TR/html4/struct/links.html#h-12.2.3

So your solution seems right. I think there might be something else going on (browser unable to scroll to your desired location, margin/padding going wrong) which messes up the scrolling.

Другие советы

You can use the following: < a name="anchorName" href="#anchorName2> < /a>

<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>

The anchor will then jump to whatever < a > tag has that name.

Here's a fiddle.

Could this "container class" be affecting the links?

.container {
  padding-right: 225px;
  padding-left: 30px;
  margin-right: auto;
  margin-left: auto;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top