I'm currently developing a website that utilizes bootstrap 4. I have successfully fixed the <nav>
element to the top of the page using the fixed-top class. Despite applying padding-top to the <body>
tag as recommended, I am encountering an issue where the top of the anchored area, particularly the headers, gets hidden behind the navigation bar.
To help illustrate my problem, I have provided a simple HTML page below for reference. By clicking any of the links at the top that link to a named anchor within the page, you will notice that the header is obscured by the navigation bar.
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35575a5a41464147544575011b031b07">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<style>
body {
padding-top: 70px;
}
</style>
</head>
<body>
<nav class="navbar fixed-top navbar-light bg-light">
...
...// This part of the code has been omitted for brevity.
...
</div>
</body>
</html>
Is there a way to ensure that when navigating to #anchor1
on this page, the Anchor 1 header is visible to the user? Currently, if a user clicks the "Anchor 1" link and lands in the middle of a paragraph, it can be confusing. Any advice on how to solve this issue would be greatly appreciated.