Why does my h1 content appear over a fixed navigation bar component?

Problem

The issue I am facing is that the content of my h1 element is overlapping with my navbar.

Possible Solutions Tried

I have attempted to adjust the z-index of the nav element and added margins to both the container containing the h1 and the nav element, but neither solution resolved the issue.

Contextual Information

In my NUXT setup, I have a default.vue file in my layouts folder structured like this:

<template>
  <div class="container">
    <Navbar/>
    <Nuxt/>
    <img src="revue/assets/nuxtjs-typo.svg" alt="nuxt-typo">
  </div>
</template>

<script>
import Navbar from '../components/Navbar.vue';
export default {
  components: {
    Navbar
  }
}
</script>

Within the pages section, I have an index.vue file where the problematic h1 element is located:

<template>
  <div class="container">
    <h1>This text overlaps the navigation bar</h1>
  </div>
</template>

<script>
export default {}
</script>

<style>

html, body {
    margin: 0;
    padding: 0;
}

h1 {
    color: #2F495E;
    font-family: 'Quicksand', sans-serif;
    font-size: 1em;
    text-align: center;
}

</style>

Lastly, in the components folder, there's a Navbar.vue component defined as follows:

<template>
    <nav>
        <ul>
            <li>
                <img id="nuxticon" src="../assets/nuxt-icon.png" alt="nuxticon">
            </li>
            <li>
                <img id="nuxttext" src="../assets/nuxtjs-typo.svg" alt="nuxttext">
            </li>
            <li>
                <NuxtLink to="/docs">Explore</NuxtLink>
            </li>
            <li>
                <NuxtLink to="/about">About Us</NuxtLink>
            </li>
            <li>
                <NuxtLink to="/field">Add Restaurant</NuxtLink>
            </li>
            <li>
                <NuxtLink to="/damage">Contact</NuxtLink>
            </li>
        </ul>
    </nav>
</template>

<style>


nav {
    position: fixed;
    box-shadow: 0 1px 3px -3px gray;
    width: 100vw;
    height: 8vh;
    top: 0;
}

nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
}


nav ul li {
    display: flex;
    align-items: center;
}


a {
    font-size: 1.5vh;
    margin-left: 2vw;
    text-decoration: none;
    color: #2F495E;
    font-family: 'Quicksand', sans-serif;
    text-transform: uppercase;
}

#nuxttext {
    height: 3vh;
    width: 10vw;
    margin-right: 8vw;
}

#nuxticon {
    height: 5vh;
    margin-right: 0.5vw;
}

a:hover {
    color: #08C792;
}


</style>

Despite these configuration settings, the h1 text remains positioned on top of the navbar instead of below it as intended.

Answer №1

The use of position: fixed on the nav element is causing it to be taken out of the normal document flow, resulting in the h1 element not being aware that it needs to be offset accordingly. To fix this issue, you can either remove the fixed positioning or add a margin-top of 8vh (which corresponds to the height of the nav element).

If you're looking for a ready-made solution using Vanilla CSS, check out this link: https://play.tailwindcss.com/eN9umaRtr5

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

Using a diverse class for enhancing the PrimeVue dialog's maximizable feature

I'm currently working with the PrimeVue Dialog component. My goal now is to apply different styles depending on whether the dialog is maximized or not. Let's keep it simple by saying I want to change the text to bold or red when the dialog is max ...

Guide to continuously play the animation, Version 2

I have been struggling with an animation that I need to loop indefinitely. The problem arises when trying to use animation-iteration-count: infinite. It seems like no matter where I place it in the code, whether within the keyframes or normal CSS rules, it ...

Creating a file in JavaScript from text is a straightforward process that involves utilizing built

I'm currently working on some JavaScript code that will trigger a download of a file directly in the browser. I have successfully obtained the file content as bytes in a string, and now I need to pass this string to a function that will create a file ...

How can I troubleshoot the overflow-y problem in a tab modal from w3 school?

https://www.example.com/code-sample overflow: scroll; overflow-y: scroll; When I type a lot of words, they become hidden so I need to use overflow-y=scroll. Despite trying both overflow: scroll; and overflow-y: scroll;, I have been unable to achieve the ...

Is it possible to change %20 in a URL to a hyphen?

Is there a way for my search form to display %20 in the URL when I fill the input field with spaces? For example: Basketball coach Current output: basketball%20coach Desired output: basketball-coach <form action="/tag/" id="form-hockey_v1" name=" ...

Header reference differs from the document referrer

this is the request header: GET / HTTP/1.1 Host: localhost:3002 Connection: keep-alive sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96" sec-ch-ua-mobile: ?0 User-Agent: ...

Get hexa values from a colorpicker and use them as a background in an angularjs application

I'm currently working on an angularJS project and I've implemented an HTML color picker. My goal is to assign the selected color from the color picker to my div element, ensuring that the values are in hexadecimal format. Below is a snippet of my ...

Tips for choosing multiple files with the Ctrl key in a list item element:

We have decided to create our own browsing functionality due to the limitations of the existing HTML browse feature. While using the HTML browse, we can only select multiple files by pressing the Ctrl key, and we want to replicate this feature in our custo ...

I relocated the navigation HTML code to a new file and as a result, the JavaScript functionality is

After successfully implementing the hamburger icon animation in my navbar using JavaScript, I decided to move the nav code to a separate file for better organization. However, the decision resulted in an error where clicking on the burger icon returned a m ...

What could be causing my custom CSS to not take effect on a progress bar within my JSP page?

Struggling to incorporate a progress bar into my JSP page to track order status, I'm facing issues with applying custom CSS. Despite using !important to override conflicting styles, it seems like other frameworks (such as Bootstrap) might be taking pr ...

Instructions for submitting information from a web form using Python without needing to know the form's ID or name

I am currently attempting to automate the submission of data into the online forms found on this webpage: Unfortunately, I am unable to determine the specific names of these forms by inspecting the source code. I have tried using the requests python modul ...

Having trouble defining the chosen option through JavaScript

I encountered an issue while attempting to set the selected option through JavaScript. I have created a select element and populated it with options from MySQL using PHP, like so: <select class="form-control input-group-lg" name="progress ...

access denied on image links

While developing a web app with Angular5, I encountered an issue regarding retrieving image URLs from the 4chan API. Each post in my database contains an image URL, however, when I try to access it through my app, I receive a 403 forbidden error in the con ...

The HTML <select> element is currently styled with a locked CSS, but I am looking to have it displayed with the default

Unfortunately, I am unable to make changes to the CSS file at this time. The current styles in the CSS file are as follows: font-size: 13px; padding: 6px 4px; background-color: rgb(238, 238, 238); border: 1px solid rgb(204, 204, 204); clear: both; margin- ...

Receive WordPress Post Updates with Complete HTML Formatting on Slack

After I publish a new post on Wordpress, a Slack notification plugin successfully sends notifications to a specific channel using the Slack API. However, my goal is to include the post content with proper formatting and HTML tags in the notification messag ...

Saving the subtracted value from a span into a cookie until the checkbox is unchecked - here's how to

I am working on a piece of code that includes numeric values within a span. When the checkbox is clicked, it subtracts 1 from the main value, essentially reducing the total value. How can I achieve this so that even after the form is submitted, the deducte ...

How to truncate text in a cell of a Vuetify data table using CSS styling

Is there a way to truncate text in a cell using CSS without it wrapping around or overflowing? The ideal CSS code should include: .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } However, the current implementation caus ...

What about a CSS element that is partially fixed?

I distinctly recall coming across an example of this not too long ago, although I am struggling to locate the specific website. It involved a button or something of that nature situated at the top of the screen, which then remained in place as you scrolle ...

Tips for creating an empty column in each succeeding row of a grid layout

Is there a way to create a grid layout with divs that leave space on the left side of each subsequent row? For example, having 4 div boxes in the first row, 3 in the second, 2 in the third, and so on. Demo https://i.sstatic.net/Gli6L.png Styling in CSS ...

Access information from multiple div elements using JavaScript data-attributes

Having trouble retrieving data-attribute values from multiple divs with the same class when clicked. The goal is to display the data value of the clicked div. function playSound(e) { const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`) ...