Anchor Text Hidden by Sticky Header

My website has a sticky header that floats above the content. When I include page anchors, the page scrolls so that the anchor is at the top. The only issue is that the header covers up the text beneath it.

Is there a solution for this problem? I can't adjust the position of the anchor because there are multiple on the page with varying amounts of text following. My initial idea was to scroll to a height above the anchor.

Thank you, David

Answer №1

If you're seeking a solution, consider the :target pseudo element. This feature allows you to target the element specified with a #-mark. For more information, visit this link.

Answer №2

Dealing with a similar issue, I devised a solution in the form of a rule like the one below:

A.named:target {
    display: inline-block;
    height: 120px;
    margin-top: -120px;
}

To resolve the problem, I assigned the "named" class to specific anchor tags that required the browser to scroll to. By doing this, I created a 120px space between the top of the browser and the bottom of the anchor-containing element. This layout adjustment factored in around 80px for the header and an additional 40px to accommodate the H2 headings I had linked to. The negative margin effectively offset the positive one, preserving the appearance of my page.

I trust this explanation proves useful!

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

Concentrate on a specific component within an overlay using jQuery

How can I focus on a specific area within an overlay when adding an item to the cart? I want to make the rest of the overlay darker and the targeted area more visible. See a quick mockup here: https://i.sstatic.net/UpJuc.png Here's the HTML code: & ...

How to Extract Minutes in Datatables Timestamps and Apply Custom Styling

Working with Datatables v1.10 Right now, my table is showing a date in the second column in the format 17-04-2019 14:34, which is how it's stored in the database. The filtering and searching functionality are all working as expected. The current HTM ...

The dilemma of calculating the total width of jQuery's list items

I am in the process of creating a submenu that should look like this: HTML: <ul class="mainMenu clearfix"> <li><a href="#">Eurodan huset</a></li> <li><a href="#">Hustyper</a></li> <li&g ...

I possess a button that decreases the value of a number in the database when pressed. I desire for this action to occur repeatedly without fail

I have a button that, when pressed, decreases a number in my database by one. I want this action to decrement the number each time it is clicked. Code in HTML and PHP <form method="post"> <div><?php $username = "root" ...

The display: table attribute is proving to be ineffective in creating the desired table layout. I am seeking alternative ways to

Is there a way to create a table using the CSS property display: table without utilizing the table element? I've searched for examples, but haven't found anything that has been helpful. Can someone please provide a fiddle of a table with a minimu ...

CSS- Strategically placing and centering images above specific keywords in (any) HTML content without disrupting the flow of text

My main objective involves dynamically inserting images above text on any given page using a content script. The challenge lies in maintaining the proper alignment of the text after adding the images. To achieve this, I surround the words where the image i ...

Looking to adjust the positioning of text being inserted into a column - unable to utilize text-align or float properties

I'm struggling to position my text in a specific area within a column using CSS. Our app displays a price when a quantity is selected, but I can't seem to center the $14 under 'Item Total'. Even using float: center; hasn't worked f ...

How can I extract a specific portion of HTML content using C#?

I am working on a page where I need to extract a substring using the following code: static string GetBetween(string message, string start, string end) { int startIndex = message.IndexOf(start) + start.Length; int stopIndex ...

Verify if the link includes https:// while using angularjs

In my angular app, there is a lot of data stored in JSON format. [ {"link": "https://stackoverflow.com"}, {"link": "https://stackoverflow.com"}, {"link": "id-aW783D"}, //This data is incorrect {"link": "https://stackoverflow.com"} ] However, the ...

The full height of the image cannot be captured by html2canvas

It baffles me that html2canvas is failing to capture the full height of the div. html2canvas($container, { height: $container.height(), onrendered: function(canvas) { var data = canvas.toDataURL('image/png'); ...

Tips for designing a search bar using Angular

search : ____________ I am interested in designing a search bar functionality that automatically triggers when the user inputs 8 or more characters. The input text will be stored in a variable, the search bar will be reset, and the backend API will be che ...

What etiquette should be followed when using the enter key while a file input is selected?

I have a straightforward form with a file input and a submit button. Our 508 compliance testers are encountering an issue during testing. When navigating to the FILE input field and pressing 'enter,' Internet Explorer submits the form. As far as ...

Separate the paragraph within an HTML string and eliminate any paragraph that is empty

I need help splitting a string of HTML into an array list, with the condition that the paragraphs should not be empty. Each paragraph should contain some normal text, and if it only contains HTML text without any normal text like: <htmltag>&nbsp; ...

Issue with PHP/HTML header() function not directing to URL page

Situation: In my member database overview, users can click on an 'update member' link in a table that redirects them to a page displaying the data of the selected member. The URL receives the parameter lid.php?lidnummer=4 (or any other ID). On t ...

Modifying .vue files within Laravel seems to unexpectedly impact unrelated CSS styles

I've been working on a Laravel project that involves building Vue components. Strangely, every time I update a .vue file and add it for a commit, modifications are also made to the app.css and app.js files. These changes seem to be undoing a particula ...

Create a dynamic animation effect for the placeholder in an input field that triggers when the user starts typing

Have you ever come across interactive demos like this one? I've noticed that most examples involve creating a new element. parent().append("<span>" + $input.attr('placeholder') + "</span>"); Is there a way to make the placehol ...

Adjust the height and eliminate gaps between rotated divisions

I'm currently working on a floating menu that includes several links. I've successfully applied a CSS style to rotate the menu vertically (-90deg), but I'm facing an issue with the height being greater than desired. How can I reduce the heig ...

What methods can be used to customize the font and background color of a website for different user groups?

Trying to incorporate a template into my project. My client has requested the following: The regular user area should feature a blue background. The professional user area should have an orange background. Is there a way to set up a condition to change ...

Saving the content of a div as a PDF

There are several aspects to consider when it comes to this question, but I'm having trouble finding the information I need. Hopefully someone can provide an answer. Essentially, what I want to achieve is: Imagine a div that is 400 X 400 px in size. ...

Ways to integrate html and php together

I'm currently working on integrating PHP with an HTML form. Here is a snippet of my code: <? php $path = "books /"; $books = opendir ($path); while (($book = readdir ($books))! == false) { if (substr ($book, -4) === ".txt") ...