The Sticky Navigation Bar Disappears After a Certain Scroll Point

Looking for some help with my website's navbar - it works fine until I scroll past the blue section, then it disappears along with other elements. Any suggestions on how to fix this? Thanks!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Elsa Frankel | Portfolio</title>
    <link rel="stylesheet" href="styles.css">
</head>
<nav id="navbar">
    <h1>My Name</h1>
    <div id="nav-buttons">
        <a href="#home">Home</a>
        <a href="#projects">Projects</a>
        <a href="#resoucres">Resources</a>
        <a href="#consulting">Consulting</a>
    </div>
    <div id="socials">
        <a href="" id="linkedin">icon</a>
        <a href="" id="tiktok">icon</a>
        <a href="" id="email">icon</a>
    </div>
</nav>
<body>
...
@import url('https://fonts.googleapis.com/css2?family=Outfit:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e295858a96a2d3d2d2ccccdbd2d2">[email protected]</a>&display=swap');

* {
    margin: 0;
    padding: 0;
    scroll-behavior: smooth;
}

body {
    position: absolute;
    top: 0; /* Header Height */
    bottom: 0px; /* Footer Height */
    width: 100%;
    height: 100%;
    font-family: "Outfit", sans-serif;
}

nav {
    background-color: #F8F8F8;
    position: sticky;
    height: 9%;
    box-shadow: 0px 2px 10px #4d4d4d;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0 2em;
    top: 0;
    z-index: 999;
}

#nav-buttons a{
    margin: 0 0.7em;
}

h1 {
    font-weight: 800;
    font-size: 1.5em;
}

.body-page {
    height: 100%;
    width: 100%;
    background-color: brown;
}

#home {
    background-color: blue;
}

I tried removing the navbar from the body section and adjusting the position of body-page elements.

Answer №1

It seems like there might be an issue with the HTML structure, but the main problem lies in CSS positioning:

The nav element should be placed inside the body tag and potentially wrapped within a header. Try setting the height of .body-page to height: 100vh instead of 100%, and also remove the absolute property from the body.

body {
    font-family: "Outfit", sans-serif;
}

.body-page {
    height: 100vh;
    width: 100%;
    background-color: brown;
}

Check out this CodePen link to see how these adjustments could improve the layout: https://codepen.io/giovannimanetti11/pen/zYQrMEN

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

A unique string containing the object element "this.variable" found in a separate file

Snippet of HTML code: <input class="jscolor" id="color-picker"> <div id="rect" class="rect"></div> <script src="jscolor.js"></script> <script src="skrypt.js"></script> Javascript snippet: function up ...

Discover the possibilities of setting the dimensions of your anchor tags using only inline-block spans

Can anyone help me understand what is happening with this small piece of HTML code? http://jsbin.com/akome5 When viewed on various browsers such as FF4, Chrome10, IE9, IE8, Opera 11, the layout of the element appears like this: Hmm, why is this happenin ...

Dynamic content displayed within adjacent div elements

I am currently working on a project where I am dynamically generating an outline by creating panels and labels in ASP.NET. Each node in the outline is defined by an outline number and outline text, which are obtained from a database that defines the relati ...

scrollable header within the confines of the container

I have been trying to find a solution for my scrolling issue, but I just can't seem to get it right. I want the content within a div to scroll inside its container without affecting the header. Here's the updated JSFiddle link with the jQuery cod ...

Looking for a way to locate words enclosed in square brackets and change them into dynamic URLs using PHP?

In my quest to locate words enclosed in square brackets, such as [word], and form a dynamic URL, I encountered a challenge. Although I attempted using the str_replace() function to identify the word, it resulted in generating links in this format: <a ...

Encountering a CSS syntax error within CodeSandbox when attempting to input code within brackets

Why is it that I don't see syntax errors in VSCode, but always encounter them in CodeSandbox? What could be causing this discrepancy and how can I resolve it? Any advice would be greatly appreciated. Thank you in advance. Here's an example of th ...

Using JavaScript, create a set of buttons within a div element and implement

$(document).ready(function() { $('#b1').click(function() { $('#uch').toggle("slow"); }); $('#b2').click(function() { $('#uch2').toggle("slow"); }) }) Although I'm not a program ...

How can I apply both Css and Bootstrap styles to an element in Next.js?

I'm having trouble incorporating the Bootstrap class sticky-top into another CSS style element. I attempted to achieve the same effect without Bootstrap by adding position: sticky, top: 0 in the CSS, but it didn't work as expected. The issue aris ...

Count the base in MySQL based on the $_SESSION['username']

I am seeking a solution to determine how many times the same username appears in 2 or more tables. The username I need to search for will be selected from $_SESSION['username'] First Table | id | username | date | | 1 | Mart |28-5-13| | 2 ...

Is it not possible to change node labels in D3.js after clicking on a node?

After being inspired by this link, I successfully created a basic network visualization app using D3.js. The app reads node names from a textarea on an HTML page and then constructs a network where all nodes are interconnected. All the relevant code can ...

Leverage ajax/js to dynamically refresh a single select tag within a set of multiple

While working on a project, I encountered a challenge while using JavaScript to update a <select> tag within a page. The specific issue arises because the page is designed in a management style with multiple forms generated dynamically through PHP ba ...

Guide on setting the value of a select element in Vue Core UI

Apologies for the newbie question, as I am just starting out with Vue.js. I have recently started using CoreUI, but I am having trouble finding detailed documentation or tutorials on CoreUI+Vue integration. Specifically, I am working with the <CForm> ...

The background image of my bootstrap carousel is not responsive to changes in the browser window size

Hey there, I'm new to the world of programming and currently working on a project to create the front end of my personal website. I've opted to utilize a bootstrap carousel background image slider in my index.html file. However, I've noticed ...

Utilize text wrapping to ensure a fixed maximum height for content display

I am in need of a div that contains text spanning multiple lines, with both a fixed width and a maximum height. Currently, I have applied the CSS property overflow: hidden;. However, my issue arises when the last line of text exceeds the maximum height of ...

Determine the maximum size of a specified number of square divs that can fit within responsive parent divs

I am working on creating a grid of square divs inside a container with variable height and width. The number of square div's is predetermined. All square divs will have images with the same dimensions (similar to the example). They should align left ...

It's proving difficult for me to align my header and navbar on the same line

Recently, I've delved into the world of HTML/CSS and encountered a challenge. My goal is to align my header (containing an h1 tag) and navbar on the same line. Ideally, the header should float left with the navbar positioned closely to its left. Howev ...

Tips on adjusting the color of a link once it has been clicked?

Looking for a link with a specific style? a { color: #999; &:hover { color: #008da0; } &:visited { color: #999; } /* I added this to test if it's gonna fix it, but it didn't */ } Upon clicking the link, it turns blue and remains s ...

Using Python and Selenium to Scroll Down the Page (with Two Separate Scrollbars)

I need help scrolling down the conversation section on Facebook Messenger. There are 2 scroll bars on the page, and I specifically want to scroll down scroll bar number 1 (see image) Click this link to access the page (make sure you are logged in and hav ...

How can I make a bootstrap container maximize the available viewport space?

I've come across several similar posts, but none seem to address my particular dilemma. My challenge lies in presenting a table at the end of a bootstrap grid: <div class="container-fluid"> <!-- Various rows with different size ...

What is the best way to assign group headings to my Codeigniter view results?

One of the challenges I'm facing in my view is organizing a list like this: <? foreach($services as $service): ?> <tr> <td><?= $service->name; ?></td> <td><?= $service->format; ?></td> < ...