Navigation bar remains visible even when displaying a fullscreen image

My goal is to create a fullscreen background image, but I'm facing an issue where I can't maintain my top/navigation bar.

I've customized the template significantly from its original design.

As I'm relatively new to HTML/CSS, I'd appreciate some guidance on how to proceed. Can anyone help me with this?

Currently, the image covers the entire screen, but there's a navigation bar and header logo underneath it.

Here's a snippet of my HTML code:

<html>
  <head>
    <title>Adem Ökmen Photography</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="../layout/styles/layout.css" rel="stylesheet" type="text/css" media="all">
  </head>
  <body id="top">

    <div class="bgded2" style="background-image:url('../images/demo/backgrounds/adem%20black.png');">

      <header id="header" class="hoc clear">
        <div id="logo">
          <h1><i class="fa" > </i> <a href="../index.html"></a></h1>
        </div>
        
        <nav id="mainav" class="fl_left">
          <ul class="clear">
            <li><a href="../index.html">Hjem</a></li>
            
            <li class="active"><a class="drop" href="gallery.html">Galleri</a>
              <ul>
                <li><a href="gallery.html">Udvalgte</a></li>
                <li><a href="wedding.html">Bryllup</a></li>
                <li><a href="portrait.html">Portræt</a></li>
                <li><a href="outside.html">Udendørs</a></li>
              </ul>
            </li>
            <li><a href="contact.html">Kontakt</a></li>
            <li><a href="partyPrice.html">Festfotografering priser</a></li>
            <li><a href="portrait1.html">Portrætfotografering priser</a></li>
            <li><a href="printPrice.html">Priser på billedprint</a></li>
          </ul>
        </nav>
      </header>

    </div>
    
    <header id="imageFull" class="hoc clear">
      
      <nav id="mainav2" class="fl_left">
        <ul class="clear">
          <div id="bg">
            <img src="../images/demo/gallery/Amnah-2.jpg">
          </div>
        </ul>
      </nav>
    </header>

    <script src="layout/scripts/jquery.min.js"></script>
    <script src="layout/scripts/jquery.backtotop.js"></script>
    <script src="layout/scripts/jquery.mobilemenu.js"></script>
  
    <script src="layout/scripts/jquery.placeholder.min.js"></script>
   
  </body>
</html>

Below is a segment of my CSS code:

#bg {
position: fixed;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
}
#bg img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
}

Answer №1

Make sure your background is placed on the body or another element above the navigation bar. Additionally, avoid using position: fixed for the background image and instead use background-attachment: fixed.

You can implement it like this:

body{
  background: silver url(...) no-repeat;/*replace 'silver' with the proper URL*/
  background-size: cover;
  background-attachment: fixed;
}

header{
  background-color: red;
  padding: 10px;
  width: 200px;
  height: 200px;
}

nav{
  background-color: blue;
  padding: 10px;
  width: 180px;
  height: 10px;
}
<body>
  <header>
    <nav>
      Insert navigation items here...
    </nav>
    Header section content here...
  </header>
  Main body content here...
</body>

When using background-attachment: fixed, the background image will remain static while scrolling through the content.

Answer №2

It appears that the background image in your code is being set to the incorrect div. Consider including the background-image property within the html or body CSS instead. This adjustment should allow your navigation bar to display correctly.

I trust this advice will be beneficial to you:)

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

Experiencing difficulties with toggling the visibility of div elements when an onchange event occurs

I am experiencing some difficulties triggering an on-change event in the department drop-down field and I'm not certain if I've written it correctly. The error message indicates: Uncaught TypeError: Cannot read property 'style' of null. ...

Is it possible to enable tab navigation for a button located within a div when the div is in focus?

I have a component set up like this: (Check out the Code Sandbox example here: https://codesandbox.io/s/boring-platform-1ry6b2?file=/src/App.js) https://i.sstatic.net/ZuxdL.png The section highlighted in green is a div. Here is the code snippet: import { ...

What is the best way to make a table fill 100% of the available height

Is this a Repetitive Question? How to stretch an HTML table to 100% of the browser window height? Just like the title says, I am looking for a way to make my table element stretch to 100% height even when the content does not entirely fill the page&ap ...

The 'data-intro' property cannot be bound to the button element as it is not recognized as a valid property

I've been using the intro.js library in Angular 8 and so far everything has been working smoothly. However, I've hit a roadblock on this particular step. I'm struggling to bind a value in the data-intro attribute of this button tag. The text ...

Extract the title of a research paper from the personnel website

I am looking to extract the title and authors of journal articles from the official web pages of all staff members. For example: https://eps.leeds.ac.uk/civil-engineering/staff/581/samuel-adu-amankwah The specific section I need to access is this: https: ...

The current code lacks any form of line breaks

While attempting to edit a CSS file in Sublime Text 2, I noticed that all the code is displayed without any line breaks. This makes it difficult to read and work with. Is there a way to fix this issue and format the code into readable sections? ...

How can I use jQuery to set up form validation for an input textfield?

Check out this code snippet: <form data-test="loginForm-container" novalidate="" method="POST" enctype="multipart/form-data"> <div class="css-o5d3v1 e1ovefus2"> <div data-test="guestForm-email-wrapper" class="e1ovefus1 css-yjv4po e1eu3s ...

ASP.NET Core MVC is experiencing issues with the dropdown functionality

_Layout.cshtml: <head> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> </head> <body> @if (HttpContextAccessor.HttpContext.Session.GetString("IsLoggedIn") == null) ...

disobedient divs

I have noticed that elements on my page are breaking out of the "wrapper" div. Here is the HTML structure I am using: <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" conten ...

Invoke a specific URL during an HTML5 upload

So I've got this code that allows for file upload via drag and drop using HTML5 in the browser. $(function(){ var dropbox = $('#dropbox'), message = $('.message', dropbox); dropbox.filedrop({ // Customizing upload settin ...

Tips for nesting an anchor tag within another tag

After reviewing various inquiries on this platform, it has been commonly believed that embedding an anchor tag inside another anchor tag is not achievable. However, I recently stumbled upon a website that successfully accomplishes this and I am curious to ...

What is the best way to add a background to text that has been wrapped?

How can I achieve a background effect for text that is wrapped within a container using CSS? Is it possible to do this by referring to an image like this: . ...

Manipulate DIVs by sliding them and resizing their contents with JQuery

Can someone help me with sliding the top div up and down, and the left div left and right? I wrote some code for this but seem to be facing some issues. When I slide the left div, the center content falls down momentarily. Additionally, the code doesn&apos ...

The animation does not seem to be functioning when applied to the input type button; however, it is

I've been attempting to apply animation to an input type button but haven't had any success yet. However, the animation works perfectly on a div tag and anchor tag. ...

Troubleshooting delays in jQuery animations

Hello, I've encountered an issue with the delay in jQuery's .animation function. When quickly moving over boxes, the animation doesn't trigger; however, it works perfectly when done slowly. Any assistance on adding a 500 millisecond delay wi ...

Attempting to organize Material Design cards in a staggered formation while ensuring they are evenly spaced out within their row

I found a great MDL template to use for my website at the following link: One feature of this template is that it aligns the "cards" in three columns. I am facing a challenge as I attempt to stagger the rows of "cards" by 2 columns, then by 3 columns, an ...

Background image spacing

Can anyone explain why there is extra space after my background image in this code snippet? (red line in image highlights the spacing issue) Even though the background image doesn't have this space, it seems to extend beyond where the black color ends ...

Discovering the data from a JSON serialization in JavaScript

Within my PrintViewModel list, there is a sublist called Summary. I am working with ASP.NET MVC. @model CRC.Models.PrintViewModel; <label id="lblTotalMonthlyLoanDeduction"></label> I am serializing it using JSON. var obj = @Json.Se ...

CSS will only be visible if it is enclosed within the <style> tag

While creating a view, I noticed that my CSS is not being displayed unless it's placed inside a <style> tag. I've tried using !important without success, as well as utilizing the selector .container-fluid > .row > .d-flex > .out_pr ...

arranging bootstrap containers to create a slideshow

Looking for advice on stacking containers in Bootstrap. I'm trying to create a page that functions like a PowerPoint presentation, where clicking on an image hides the current container and reveals the next one. This requires the containers/slides to ...