Connect to a particular section of the webpage with additional top spacing

The navigation on this page is not transparent. Whenever I link to a specific part of the page, some text becomes hidden behind the navigation bar. This is illustrated in the image below: https://i.sstatic.net/h0ExX.png

What I desire is a navigation bar like this: https://i.sstatic.net/iYiL1.png

You can see in the first image that the "background" text is obscured by the navigator.

Here is my HTML and CSS code:

<!DOCTYPE html>
    <html>
    <head>
    <style>
    ul {
        position: fixed;
        top: 0;
        width: 100%;
        background-color: rgb(255, 255, 255);
        opacity: 1.0;
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        -moz-box-shadow: 0px 2px 20px -5px rgba(0, 0, 0,0.5);
        -webkit-box-shadow: 0px 2px 20px -5px rgba(0, 0, 0, .5);
        box-shadow: 0px 2px 20px -5px rgba(0, 0, 0, .5);
        padding: 5px;
    }
    li {
        float: right;
    }
    li a {
        display: block;
        color: black;
        text-align: center;
        padding: 14px 25px;
        text-decoration: none;
    }
    li a:hover {
        font-family: cursive;
    }

    h2 {
      font-size: 30px;
      font-family: Futura, Trebuchet MS, Arial, sans-serif;
    }

    h3 {
      font-size: 30px;
      font-family: Brush Script MT, cursive;
    }

    h2, h3 {
      width: 50%;
      height: 60px;
      margin: 0;
      padding: 0;
      display: inline;
    }
    </style>
    </head>

    <body>
      <header id="header">
        <ul>  
          <li><a href="#experience">Experience</a></li>
          <li><a href="#background">Background</a></li>
          <li><a href="#home">Home</a></li>
        </ul>
      </header>

      <!-- Home -->
      <table align="center" border="0" cellpadding="5" cellspacing="5", width="450", style="margin-top:100px">
      <tr id="home">
        <td>
            <div id="image">
                <img src="" style="margin:auto;width:150px;height:200px;display:block" />
            </div>
        </td>
        <td>
            <div id="section">
            <h2> sss  </h2>
            <h3>sss</h3>
                <p>ssssssss</p>
            </div>
        </td>
        
      </tr>
      
      <tr id="background">
      <td colspan="2">
            <div id="background1">
            <h2 style="font-family: Futura, Trebuchet MS, Arial, sans-serif;"> Background </h2>
            <p>Big Star was an American power pop band formed in Memphis, Tennessee, in 1971... (Full article goes here) ...The group broke up in 1974, but reorganized with a new line-up nearly 20 years later. (Full article continues)...</p>
            <hr>    
            </div>
      </td>
      </tr>
      </body>
    </html>

Answer №1

Begin by creating a fresh class

.anchor { padding-top: 90px; }

Then apply this class to any element you wish to connect to. For example:

<div id="background1" class="anchor">

From now on, when you link to this particular element, the class will automatically adjust the offset for you.

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

Mastering the art of jQuery scrolling: A step-by-step guide

Is there a way to utilize jQuery for scrolling purposes? For example, transforming this: <ul class="nav navbar-nav navbar-right"> <li class="active"><a href="#home">Home <span class="sr-only">(current)</span></a> ...

Image superimposed with vertical dimension

I have a photo with specific dimensions and I want to create a div box with a button inside the image, similar to what is shown in this example: Example Image Here is my current code attempt: .wrapper { width: auto; text-align: center; } .wrapper: ...

struggling to preserve form data using PHP and MySQL

I am facing an issue with a page that needs to display a form with checkboxes, save the results in the database, and then load the page with the checkboxes checked based on the stored data. Although I realize that my solution of floating "checked" is not ...

What could be causing the right padding to be overlooked next to the scroll bar, and what steps can be taken to address this

https://i.sstatic.net/0laRo.jpg .outer { padding: 50px; } .inner { width: 500px; height: 1000px; border: 1px solid gray; margin: auto; } <div class="outer"> <div class="inner"> <div class="content">qwerty</div> ...

Concerns with the adaptability of CSS grid rows

I'm struggling to find a solution for the issue I am facing. Is there a way to adjust each column's row height based on its content in a way that differs from the other column rows? The code snippet below demonstrates the current setup, which is ...

Controlling File Upload Edits: A Guide to Effective Management

I am facing an issue on my product page related to adding and updating products in the database. The problem lies with images not displaying correctly. During the product insertion process, everything works fine. In my aspx page, I have the following code ...

html td elements are breaking due to the application of ngFor

<table> <tr> <th>Date</th> <th>Products</th> </tr> <tr *ngFor="let x of orderdetails"> <td>{{x.orderdate}}</td> <td *ngFor="let y of x.orderproducts"> <span class="break">{{y}}</s ...

Having trouble getting JavaScript validation to function properly

I'm struggling to make validation work properly when hitting the submit button. No alert messages appear, even though I should be receiving alerts for empty fields. Can someone identify what is wrong with my code? I have tried checking the validation ...

Displaying a project in the same location using jQuery

Struggling with jQuery and positioning hidden items that need to be shown? I have two white boxes - the left one is the Client Box (with different names) and the right one is the Project Box (with different projects). My goal is to show the projects of a c ...

HTML makes column text wrapping automatic

Is it feasible to implement text wrapping into two columns or more in HTML using solely CSS? I have a series of continuous text enclosed within p tags only, structured as follows: <div id="needtowrap"> <p>Lorem ipsum dolor sit amet, ...&l ...

What is the reason behind my resizer bar not changing color to green?

Whenever I resize the bar between the West and Inner Center areas, it turns green. However, the bar between the Inner Center and Inner South areas does not change color. How can I make it turn green when resizing, including adding the orange highlight for ...

Using HTML and JavaScript to add variables into the URL within the window.location

I have been struggling to incorporate longitude and latitude into the URL. Despite researching various topics online, I have not found a solution that works for me. Below is the HTML code that showcases the issue. When you click the "Show Position" button ...

Is there a way to connect a CSS external file that is saved on Dropbox?

Is it possible to link an external CSS file stored in Dropbox with HTML? I have followed all the instructions I could find online, including clicking and pressing "Copy Dropbox Link" to generate an href link. However, it doesn't seem to be working. ...

Having trouble accessing the 'checked' property of the checkbox

I've been developing a web application using Vite, JavaScript, jQuery, and Bootstrap. I'm facing an issue where the jQuery .is(':checked') function is not working as expected on one specific page. Despite the checkboxes being checked, t ...

When pasting Arabic text into an input box, the words in HTML appear to be jumbled and shuffled around

When I replicate this text يف عام and input it into a box, the output is shown as follows عام يف ...

Three divs arranged side by side with responsive design for mobile viewing

This code generates 3 divs for display. However, I am looking to optimize them for mobile devices. What steps can I take to accomplish this? Currently, the divs are oriented to the left and are not visible on a mobile device. I would like them to display ...

Is there a way to integrate PHP into HTML without using a specific tag?

Before diving into something complex, I wanted to start with a basic PHP and HTML project. Unfortunately, my HTML page doesn't seem to be processing the PHP code correctly. Below is the PHP code embedded in my HTML: <?php echo '<p>Hell ...

Tips on using the Hover property in CSS for an element that includes both :after and :before properties

I've created a hexagon using CSS after and before properties, and now I'm attempting to add a glowing effect around the hexagon when hovering. It works perfectly for the center of the hexagon but not for the top and bottom points of the shape. ...

Generate an embedded iframe displaying a linked code snippet

I manage an online store and once a courier has been dispatched, I send out an email to customers with tracking information for their shipments. To streamline this process, I have implemented an input field (Code provided below). In this field, when a us ...

Unexpected vertical line in MUI5 Stepper appears when invoking from a function

Greetings! I'm currently working on developing a MUI5 vertical stepper, but I've encountered an issue when rendering steps from a function. Specifically, there is an extra connector line appearing on top of the first step. If you'd like to ...