What could be the reason for the page failing to navigate to the intended section on the screen?

Here is the HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>A+Tec</title>
<style type="text/css" >
* {
  margin: 0px;
  padding: 0px;
}
#wrapper {
  width: 100%;
  height: auto;
  background-color: #ABEBC1;
  position: fixed;
}

#nav {
  width: 1400px;
  height: auto;
  margin: auto;
}

.buttons {
  height: 25x;
  width: 200px;
  background-color: #ABEBC1;
  background-repeat: repeat-x;
  float: left;
  margin: 0px 10px;
  text-align: center;
  font-family:"Arial Rounded MT Bold", Arial, Helvetica, sans-serif;
}
</style>
</head>

<body>

<div id="wrapper">
  <div id="nav">
  <div class="buttons">
  </div>
  <div class="buttons"><a href="#C4">About Us</a></div>
  <div class="buttons">Our Staff</div>
  <div class="buttons">New Admissions</div>
  <div class="buttons">A-Level</div>
  <div class="buttons">GCSE</div>
  <div class="buttons">Contact Us</div>
  </div>
</div>
<br/>
<p>
<a href="#C4">See also Chapter 4.</a>
</p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>

<h2><a id="C4">Chapter 4</a></h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 5</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 6</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 7</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 8</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 9</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 10</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 11</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 12</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 13</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 14</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 15</a></h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 16</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 17</h2>
<p>This chapter explains ba bla bla</p>
</body>
</html>

I utilized the HTML code from an example on w3schools that enables users to navigate to different sections of a webpage via hyperlinks. The issue I am facing is when clicking on "Chapter 4" or "About Us," it redirects to a different section instead of the intended one. Is there any way to resolve this problem?

EDIT: It appears that the navigation is functioning correctly; however, the targeted section appears beneath the top bar, obstructing the view. Is there a method to adjust this so that the content displays below the top bar?

Thank you

Answer №1

To specify the ID, there's no need to insert it within an <a> tag in the heading. Simply do this:

<h2 id="section5">Section 5</h2>

For resolving the fixed header issue, you can refer to these useful resources:

In terms of links directing to Section 2, this may be impacted by your browser window's height constraints. The link will only scroll as far as the content permits. You'll still notice that the targeted Section 5 heading is highlighted with the use of :target. For example:

#section5:target {background: blue;}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for integrating DataTables selection filtering functionality

Here's a snapshot of my screen I'm attempting to utilize data tables This is what I have on the main page $('#student-listing-table').dataTable(); $('#student-listing-table').find('label').html('Search By Nam ...

My PHP script encountering issues retrieving POST values

I am encountering an issue with my HTML login form and PHP processing. The form is supposed to POST values to /user.php, where my authentication class handles the login process. However, I am having trouble getting the form to actually submit the data. He ...

Suggestion for a script that graphs in PHP

Searching for a user-friendly PHP-based graphing script that can generate image-based charts for e-mailing or printing purposes. Looking into PHPGraphLib, but open to other recommendations, whether commercial or GNU. Flash-based solutions are not suitabl ...

What causes the disparity in height between a textbox and the encompassing span element?

What causes the discrepancy in element heights when looking at the code below? <span id="spanner" style="margin:0;padding:0;border:0;outline:0;"><input type="text" /></span> If you check the height of the text box, it will be shown as 1 ...

Adjust the border color of an image when a radio button option is selected

I manage an online shop using WooCommerce that includes a filter for selecting product colors. The available color options are black, blue, and white. When customers choose a color option, only the products in that specific color will be displayed automati ...

Nesting divs that soar within a contained div (not spanning the entire page)

I need the div elements to move within another div container instead of flying over the entire page. What changes do I need to make in the code to achieve this? $(document).ready(function() { $('.balloon').each(animateDiv); }); function ma ...

Is the `visibility: hidden` property not functioning as expected?

I am trying to conceal the script for the photoset until it is fully loaded, but unfortunately the code below does not seem to be effective: JavaScript $('.photoset-grid').photosetGrid({ rel: $('.photoset-grid').attr("data-id"), gutte ...

Flashing on objects, Chrome-exclusive, utilizing background-blend-mode exclusively

Our website, www.desirio.com, utilizes a background-image on the body with the following CSS property: background-blend-mode: luminosity An issue we have noticed in Chrome is that when hovering over elements, strange white lines randomly flash on the scr ...

Static components shift around in WKWebkit

An application that is native contains a WkWebview along with a blue native navigation bar. This app is being used on an iPad running iOS 10.3.1 and Safari 10 The bounce feature is currently enabled. Within the WkWebview, there is a brown overlay positi ...

The dimensions of the background for a span element

I have a span element with a background-color applied to it. Is there a way to adjust the size of this specific background? I attempted using background-size: auto 2px;, but it did not produce the desired effect. I am looking to make the background color ...

Can you explain the function of .modal('dispose') in Bootstrap 4?

As stated in the documentation, the .modal('dispose') method is used to destroy a modal. .modal('dispose') This method destroys the specified modal element. However, after creating an eventListener like this: $('#myModal') ...

"Struggling to make the 'overflow: hidden' property work for an absolutely positioned

I'm struggling to conceal an absolutely positioned image within a CSS grid layout. Below is the code snippet: HTML: <div class="relative-parent"> <div v-for="item in 12" class="hiding-parent"> <div c ...

Weak Password Alert

After spending hours writing code for form validation and password strength checking, I encountered a roadblock. The form validates successfully, but the password strength indicator is not updating as expected. Despite double-checking the logic in my code ...

Discovering the Magic of Bootstrap 2.2.1 Popovers

I've been attempting to implement Bootstrap popover element in my application. Unfortunately, it doesn't seem to be working as expected. The popovers work fine when placed outside of a div with the overflow style property set. Oddly enough, thi ...

Prevent the border from shrinking upon being clicked

I'm currently working on customizing an accordion using jQuery for the animation effects. However, I am facing an issue where clicking on the accordion header causes the border around the plus sign to shrink in size as well. My goal is to only have th ...

Step-by-step guide on creating a unique Bootstrap Nav overlay effect

My Bootstrap navigation bar is functioning properly However, I am facing an issue in adding an overlay to the NAV menu on mobile screens I am using Bootstrap and Umbraco 7 <nav class="navbar navbar-fixed-top navbar-default" role="naviga ...

Trouble aligning dynamic inline-block <h1> tag with text-align: center

One of my Angular directives has a feature that scrolls through words in an array and presents them as if they are being typed out in real-time. I'm facing an issue with aligning the h1 tag that displays these dynamically changing words to be centered ...

Resize image to fit within a div using Bootstrap

I'm attempting to resize some images to fit into horizontal cards created with Bootstrap-5, but I'm having trouble filling up the div completely. I've been using a main.scss file to manage the Bootstrap CSS and have tried using classes like ...

CSS: Stretch the text background to match the width of the container

Is there a way to make the background color of a text cell stretch the width of its container div, rather than just the text itself? https://i.sstatic.net/E3zeL.png Here's the HTML code snippet: <div class='col-md-4'> <span class= ...

Login form with AJAX for seamless submission without page refresh

I found a helpful tutorial on creating a login form at This tutorial focuses on authenticating against our LDAP server. However, I am running into an issue with the following line of code: success: function(){ $('form#submit').hide(function() ...