The content is being pushed down by the responsive navigation bar

While the navbar is in normal non-responsive mode (I'm not sure if that's the right terminology) on Chrome and you scroll down, the logo image stays behind the menu. However, when the screen width shrinks and the menu collapses, clicking the icon to expand it pushes the logo image down. I want the logo image to remain behind the menu when viewed on mobile.

Later on, I might have some content that I do want to be pushed down, but for now, I don't want this logo to be affected. It could be made part of the background, but I think it would look better as a separate image.

Link to Full Code

CSS

#logo {

    width: 50%;
    margin: 80px auto;

}

.topnav {

  background-image: url(http://www.buffettworld.com/images/navmenubg.png);
  background-size: 100%;
  font-family: 'Pathway Gothic One', sans-serif;
  margin-top: 10px;
  position: fixed;
  top: 0;
  width: 100%;
}


.topnav a {
  float: left;  
  display: block;
  color: white;
  text-align: center;
  padding: 14px 25px;
  text-decoration: none;
  font-size: 21px;

}

... // CSS styles continued

<p>HTML</p>

<pre><code><div class="topnav" id="myTopnav">
  <a href="#home">HOME</a>
  <a href="#news">NEWS</a>
  <a href="#news">TOUR</a>
    ... // HTML structure continued
        </div>
          <div class="dropdown">
    <button class="dropbtn">MUSIC 
      <i class="fa fa-caret-down"></i>
    </button>
    <div class="dropdown-content">
        ... // HTML content continued
  </div>
        ... // More HTML content
</div>


<script>
function myFunction() {
    var x = document.getElementById("myTopnav");
    if (x.className === "topnav") {
        x.className += " responsive";
    } else {
        x.className = "topnav";
    }
}
</script>



    <div id="logo">

        <img src="http://www.buffettworld.com/images/logo.png">
    </div>

Answer №1

Adjust your topnav positioning to absolute within the media query for max-width: 600px

.topnav.responsive {position: absolute;}

Hopefully this solution helps :)

#logo {

width: 50%;
margin: 80px auto;

}

.topnav {

  background-image: url(http://www.buffettworld.com/images/navmenubg.png);
  background-size: 100%;
  font-family: 'Pathway Gothic One', sans-serif;
  margin-top: 10px;
  position: fixed;
  top: 0;
  width: 100%;

}


.topnav a {
  float: left;  
  display: block;
  color: white;
  text-align: center;
  padding: 14px 25px;
  text-decoration: none;
  font-size: 21px;

}

.topnav .icon {
  display: none;
}

.dropdown {
    float: left;
    overflow: hidden;

}

.dropdown .dropbtn {
    font-size: 21px;    
    border: none;
    outline: none;
    color: white;
    padding: 14px 25px;
    background-color: inherit;
    font-family: inherit;
    margin: 0;

}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;

}

.dropdown-content a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.topnav a:hover, .dropdown:hover .dropbtn {
  background-color: #b1d235;
  color: white;
}

.dropdown-content a:hover {
    background-color: #ddd;
    color: black;
}

.dropdown:hover .dropdown-content {
    display: block;
}

@media screen and (max-width: 600px) {
  .topnav a:not(:first-child), .dropdown .dropbtn {
    display: none;
  }
  .topnav a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {position: absolute;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  .topnav.responsive .dropdown {float: none;}
  .topnav.responsive .dropdown-content {position: relative;}
  .topnav.responsive .dropdown .dropbtn {
    display: block;
    width: 100%;
    text-align: left;
  }
}

.sticky {
  position: fixed;
  top: 10px;
  width: 100%
}
<div class="topnav" id="myTopnav">
  <a href="#home">HOME</a>
  <a href="#news">NEWS</a>
  <a href="#news">TOUR</a>
    <div class="dropdown">
    <button class="dropbtn">JIMMY 
      <i class="fa fa-caret-down"></i>
    </button>
    <div class="dropdown-content">
<a href="#">BIOGRAPHY</a>
<a href="#">AVIATION</a>
<a href="#">INCIDENTS</a>
<a href="#">BUSINESS EMPIRE</a>
<a href="#">CONTACT JIMMY</a>
    </div>
</div>
  <div class="dropdown">
    <button class="dropbtn">MUSIC 
      <i class="fa fa-caret-down"></i>
    </button>
    <div class="dropdown-content">
<a href="#">ALBUMS</a>
<a href="#">SONGS</a>
<a href="#">CHART HISTORY</a>
<a href="#">TRIBUTE BANDS</a>
  </div>
</div>
<a href="#about">SET LISTS</a>
  <a href="#about">ABOUT</a>
<a href="#about">ADVERTISE</a>
<a href="#about">CONTACT</a>
  <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a>
</div>


<script>
function myFunction() {
    var x = document.getElementById("myTopnav");
    if (x.className === "topnav") {
        x.className += " responsive";
    } else {
        x.className = "topnav";
    }
}
</script>



<div id="logo">

<img src="http://www.buffettworld.com/images/logo.png">
</div>

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

Show all span elements in a map except for the last one

Within my ReactJS application, I have implemented a mapping function to iterate through an Object. In between each element generated from the mapping process, I am including a span containing a simple care symbol. The following code snippet demonstrates t ...

Include various categories into the div containers of the listed items within the query outcomes

Is there a way to customize div styles based on query results? I want to differentiate the styles of divs in the result list based on their content. For example: I'd like bird names in the result list to have different div styles compared to other a ...

Tips for positioning a button beside a ListItem

Is there a way to place a button next to each list item in ASP.NET? <asp:CheckBoxList ID="lstBrembo" runat="server"> <asp:ListItem Text="Popular" Value="9"></asp:ListItem> // <--- trying to add button here, but getting parse error ...

Display fewer search results initially and have the option to view more when hovering

I am working with a PHP function that generates a ul element. <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> I am looking to display the list in a li ...

Adapt appearance according to the length of the text

Currently, I have an array that stores multiple strings based on displayed charts. My objective is to find the longest string within this array. So far, this task has been executed without any issues. The code snippet for this process is as follows: var ...

Div elements containing identical content and styled in the same manner exhibit distinct dashed borders

After designing a pen with a unique twist, you'll notice that the first div has a border-bottom, while the second has a border-top. What's interesting is that the border on the second div is not the same as the first. Visit this link to see for ...

Is there a way to increase the spacing between the titles of these progress bars?

Ensure your responsiveness by enabling the Toggle Device Toolbar on your browser I'm attempting to create a progress bar, but I'm facing some challenges. Firstly, I want to increase the height of the semi-transparent black background, but I can& ...

Just starting out with CSS and coding. Setting up radio buttons and divs for a simple beginner's gallery

One challenge that perplexes me is how to reposition the concealed divs below the radio buttons with labels. Check out my HTML here View my CSS code here /*color palette: abls [lightest to darkest] #eeeeee #eaffc4 #b6c399 ...

The Material UI button feature neglects to account for custom CSS styles when attempting to override the default settings

Utilizing a custom bootstrap css styles in my react app, I am seeking to enhance the default material ui components with the bootstrap styles. import React, {useState} from 'react'; import 'cg-bootstrap/core/build/cg-bootstrap-standard.css&a ...

What is the best way to line up two forms side by side?

Looking to create a login view for a webpage with two forms (one for registration and one for login) aligned side by side. Initially attempted using a table, then tried using bootstrap form groups (rows and cols) without success. Finally, aligned them in t ...

Function in jQuery to reference two different divs

I'm currently facing an issue with a code snippet that I have. The requirement is for the user to be able to hover over "Div 1" and/or "Div2" and trigger a red border around both elements simultaneously. Due to the complexity of my WordPress theme, th ...

Issues with a top navigation bar

I'm currently working on customizing a header menu to my liking but have limited experience with CSS. The header menu consists of two main items, each with a dropdown. I envision the first menu item to look like this upon hover: And for the second m ...

Is there a way to automatically redirect my page after clicking the submit button?

I'm having trouble with the code below. I want it to redirect to NHGSignin.php if 'new horizon gurukul' is entered. When I click the Next button, it's supposed to take me there but it's not working as expected. Can anyone help me f ...

Align the input labels to the right

In the demonstration below, an example is provided for aligning labels to the right of an input field. Is there a way to ensure that the input field takes up 100% of the width? Additionally, can an input be replaced with a textarea or another div element w ...

Instructions on uploading a PDF file from a Wordpress page and ensuring the file is stored in the wp-content upload directory folder

What is the process for uploading a PDF file on a WordPress page? <form action="" method="POST"> <input type="file" name="file-upload" id="file-upload" /> <?php $attachment_id = media_handle_upload('file-upload', $post->I ...

Placement of Buttons Inside a Division Tag

Is there a better way to align button 3 & 4 in a vertical column next to button 1 & 2 without using tables in CSS? See the working example below: https://jsfiddle.net/Jaron787/0te3cs66/1/ Code: HTML <div id="lse" class="display"> <di ...

A tutorial on creating dynamic text animations: sliding text effects on web pages

Does anyone know how to create a sliding in and out effect like the one on this page: ...

Clickable regions in Internet Explorer 7 that lack a specific width

Is there a way to make the clickable area of links always stretch to the parents container when the parent container does not have a fixed width? For example, check out this JSFiddle. In Firefox, the link stretches with the text and the li tag, but in IE ...

Nested CSS selector within a parent element

How can I change the color of both elements inside a custom button when the button is active? The first color is defined by the class of the button, and the second color is defined by the class of the span inside that button. CSS: .buttonClass{ color:b ...

Header Dropdown Problems

Hey there, I have a question regarding my header setup. I currently have two headers in place: Whenever I click the notification button, the dropdown menu seems to disrupt the layout of the header. Here is a screenshot for reference: Below is the CSS cod ...