The navigation bar remains fluidly fixed over the image

I've encountered a dilemma with my webpage layout. I have placed an image at the top, but I also want to add a navigation bar on top of the image. The issue is that the navigation bar appears above the image instead of in front of it. While I can use position: fixed to place the navibar at the top, it becomes troublesome when scrolling. Is there a solution to this problem?

(PS: The image is not being used as a background!)

<nav class="navbar " role="navigation">
<div class="container-fluid">
    <div class="collapse navbar-collapse navbar-right navbar-main-collapse">
        <ul class="nav navbar-nav">
            <li>
                <a> Link </a>
            </li>
            <li>
                <a> Link </a>
            </li>
            <li>
                <a> Link </a>
            </li>
            <li>
                <a> Link </a>
            </li>
            <li>
                <a> Link </a>
            </li>
        </ul>
    </div>
</div>
</nav>
<img src=" ">

Answer №1

Try this solution:

.menu {
  position: fixed;
  top: 0;
  left: 0;
}

Check out the example here: https://jsfiddle.net/px7j4tdk/

The concept is similar to what you were attempting - keeping the menu at the top of the page. However, instead of using position: absolute, which fixes the menu within the content flow, try using position: fixed, which will keep the menu in a fixed position relative to the browser window.

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

How about incorporating a loading animation for form submission?

While my code is running some calculations, I want the submit button to change from the current "RUN" state to a loading gif that I have. Clicking the RUN button should trigger a specific script to run and calculate various data, returning the results to t ...

What is the process for activating JavaScript and embedding it into an HTML document?

I am currently utilizing a JavaScript API that contains several functions. How can I incorporate it into an HTML file? One of the functions, "api.ping()", performs well on PowerShell, but I am encountering difficulties with displaying it on an HTML file. ...

Creating an inner shadow effect for geometric shapes with text inside - a step-by-step guide!

Is it possible to apply an inner shadow to geometric shapes with text inside using CSS? This is the effect I want to achieve: https://i.stack.imgur.com/XcGS2.png I followed the code provided in this thread: Required pentagon shape with right direction ...

What is the best way to format PHP emailed content from a web form?

Currently, I am working on a web contact page and facing an issue where the emails being sent arrive as plain text. I would like to enhance them by adding a background, incorporating the organization's logo, and styling the text to align with the webs ...

Could HTML code be inserted into the <Head> section of a NextJS page?

I need to add meta tags retrieved from the backend for a certain page to the Head section of my page component. In React, I know that I can incorporate HTML using <div dangerouslySetInnerHTML={{__html: response.someHtml}} />. Can this same method b ...

Ways to display text when hovering over an image link

Despite trying various techniques recommended by fellow Stackoverflow users who faced similar issues, I still encountered a problem where the text appeared below the image even after applying the suggested methods to my code. I also experimented with a me ...

Using Postgres array or JSON to display separate Bootstrap badges within an HTML document

Here is a snapshot from my live server: https://i.sstatic.net/sq83x.png In the image attached, I have been working on extracting information from arrays and JSON using Bootstrap. My goal is to display each value from the array or JSON in separate badges. ...

Attempting to assign an active class to a menu item

I've been struggling for 2 hours to create a dynamic menu, but unfortunately, I haven't had any success. That's why I decided to seek some assistance. I have an HTML menu along with some JS and CSS... $(function() { var pgurl = window.l ...

Is there a way to eliminate the <hr> tag using CSS?

Is there a way to remove a horizontal line using CSS? Here is the HTML code snippet: <div id='page'> <div id='header'> </div> <hr> </div> I attempted this method: #page hr:first-child{display:none;} H ...

Incorporating Only XSD Files into an HTML Input Tag: A Simple Guide

Is there a way to restrict a file input element to only display XSD files? I attempted the following: <input type="file" accept="text/xsd" > Unfortunately, this method is not working as it still allows all file formats to be disp ...

Adjusting the content of a span causes the parent element to shift to the left

I'm having trouble finding a solution to a specific issue that seems to be only affecting Chrome. Whenever I try to replace the text in a span element, it causes the parent anchor to shift left. You can see a demonstration of this problem here: http:/ ...

PHP's $_SESSION variable for passing data between pages

Every time I visit a new page, whether it's a login page or any other, I want to store the name of that page in a $_SESSION variable. For example, on the login page: <?php session_start(); $_SESSION['page'] = 'login.htm&apo ...

What is causing the Bootstrap accordion to not display content when clicked on?

As a beginner in web development, I am currently working on my very first website. One issue I'm facing is with incorporating an accordion-style card in my webpage. Although it allows me to click on different titles, the collapsed ones fail to expand ...

exploring numerous boxes in an engaging and educational tutorial

Explaining this in the title was a bit tricky, but what I want to create is an interactive tutorial. In this tutorial, the user will click on an area or product they want to clean or use for cleaning. After clicking, another box with relevant information w ...

Ensuring File Size and Format Compliance in Angular's HTML and TypeScript

I'm currently tackling a file upload feature on an ASP.net webpage using Angular. I have a question: How can I verify if the uploaded file is either a PDF or JPG and does not exceed 2MB in size? If these conditions are not met, I would like to displa ...

Guide on utilizing Thymeleaf for dynamic updates in a table

My code includes a segment like this: <div class="ui-table"> <div class="items"> <div class="justify-content-end d-flex"> <span class="text- ...

Displaying a carousel of cards with a stacking effect using CSS and React

https://i.sstatic.net/254kG.jpgI am looking to design a layout similar to the image provided, where cards are stacked on top of each other with three dots for toggling. Can anyone guide me on how to achieve this visual effect? ...

Adding a button label value to a FormGroup in Angular

I've been working on a contact form that includes inputs and a dropdown selection. To handle the dropdown, I decided to use the ng-Bootstrap library which involves a button, dropdown menu, and dropdown items. However, I'm facing difficulties inte ...

Set a child element's height based on its parent row-fluid using Twitter Bootstrap CSS

Can you suggest a more effective approach to set the height of a child element equal to its parent's height? I have attempted the following method without success: .child { background: none repeat scroll 0 0 #5B6567; border-radius: 5px 0 0 ...

The extension's script initiates without waiting for the entire page to finish loading

Recently, I have embarked on developing a chrome extension that requires waiting for a YouTube page to fully load before inserting a button into the existing code. Despite using getElementById() to locate the element, the script often completes execution b ...