Issue with the hamburger menu dropdown color not being applied properly

Greetings to all who are taking the time to review this query! Everything seemed to be going well until I refreshed my code after making numerous changes, and then this issue arose:

Dropdown menu lacking color:

https://i.sstatic.net/3lz5a.png

The color from the header did not transfer to the dropdown. How can I resolve this? Below is the code snippet in question:

<header id="sticky-header">
        <div class="nav">
            <label for="toggle">&#9776;</label>
            <input type="checkbox" id="toggle" />
            <nav>
                <ul>
                    <li><a href="#top">Home</a></li>
                    <li><a href="#bio">Bio</a></li>
                    <li><a href="#music">Music</a></li>
                    <li><a href="#shows">Shows</a></li>
                    <li><a href="#media">Media</a></li>
                    <li><a href="#contact">Contact</a></li>
                </ul>
            </nav>
        </div>
    </header>

header {
height: 67px;
background-color: #2b2b2b;
width: 100%;
position: fixed;
text-align: center;
}

nav ul {
margin-top: 13px;
padding: 0;
list-style: none;
}

nav li {
display: inline-block;
margin: 0.8em;
}

nav a {
font-weight: 800;
text-decoration: none;
text-transform: uppercase;
font-size: 0.95em;
padding: 0.5em;
color: #FFF;
}

nav a:hover,
nav a:focus {
color: #048575;
font-size: 1em;
}

label {
font-size: 2rem;
color: #FFF;
padding: 0.5em;
display: none;
width: 1em;
float: center;
}

#toggle {
display: none;
}

@media only screen and (max-width:650px) {
header {
    padding-top: 0em;
    padding-bottom: 0em;
    background-color: #2b2b2b;
}

label {
    display: block;
    cursor: pointer;
}

nav li {
    display: block;
    display: none;
}

nav a {
    display: block;
    padding-top: 1em;
    padding-bottom: 1em;
    border-bottom: 1px solid black;
}

#toggle:checked + nav li {
    display: block;
}
}

Apologies for the formatting inconsistencies, as copy and paste did not function properly. Thank you for taking the time to read this and for any assistance you can provide! (Any other feedback is also welcome).

Answer №1

Are you looking to match the black background of your header with the dropdown menu as well? To achieve this, you will need to apply the background style to the nav element within your media query. Additionally, you may need to adjust the margin-top property to align your navbar with the header:

nav {
  background-color: #2b2b2b;
  margin-top: -20px;
}

This can be implemented as shown below:

header {
  height: 67px;
  background-color: #2b2b2b;
  width: 100%;
  position: fixed;
  text-align: center;
}

nav ul {
  margin-top: 13px;
  padding: 0;
  list-style: none;
}

nav li {
  display: inline-block;
  margin: 0.8em;
}

nav a {
  font-weight: 800;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.95em;
  padding: 0.5em;
  color: #FFF;
}

nav a:hover,
nav a:focus {
  color: #048575;
  font-size: 1em;
}

label {
  font-size: 2rem;
  color: #FFF;
  padding: 0.5em;
  display: none;
  width: 1em;
  float: center;
}

#toggle {
  display: none;
}

@media only screen and (max-width:650px) {
  header {
    padding-top: 0em;
    padding-bottom: 0em;
    background-color: #2b2b2b;
  }
  label {
    display: block;
    cursor: pointer;
  }
  nav {
    background-color: #2b2b2b;
    margin-top: -20px;
  }
  nav li {
    display: block;
    display: none;
  }
  nav a {
    display: block;
    padding-top: 1em;
    padding-bottom: 1em;
    border-bottom: 1px solid black;
  }
  #toggle:checked+nav li {
    display: block;
  }
}
<header id="sticky-header">
  <div class="nav">
    <label for="toggle">&#9776;</label>
    <input type="checkbox" id="toggle" />
    <nav>
      <ul>
        <li><a href="#top">Home</a></li>
        <li><a href="#bio">Bio</a></li>
        <li><a href="#music">Music</a></li>
        <li><a href="#shows">Shows</a></li>
        <li><a href="#media">Media</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </nav>
  </div>
</header>

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

Achieving Horizontal Alignment in a Dropdown Menu with Bootstrap 4

I am utilizing a dropdown that contains 3 main "categories", each with multiple checkboxes for filtering search results. Below is an example: <div class="dropdown"> <button type="button" class="btn dropdown-toggle" data-toggle="dropdown">B ...

What is the best way to make this CSS arrow see-through?

My goal is to achieve this desired outcome: https://i.sstatic.net/4eTpE.png Currently, I have the following (focusing only on the left element for now): https://i.sstatic.net/nUFp1.png I am struggling to make the left arrow transparent and I can't ...

Designing a sleek border for form input fields

Seeking assistance in finding a solution as my extensive online search has been unsuccessful. Currently, I have this code to style my form labels: label { display:inline-block; height: 15px; width: 350px; float: left; padding: 5px; ...

Remove the div of the previous selection in jQuery and add the current selection by appending it, ensuring only one selection per row is allowed when

Here is a code snippet that includes buttons appending selections to the "cart" div upon clicking. The first script ensures only one selection per row when multiple buttons in the same row are clicked. In the second script, selections are appended to the ...

What is the most effective way to reduce the spacing between columns in Bootstrap while maintaining consistent spacing on the outer edges?

I have set up my bootstrap columns as shown below: <div class="col-6"> <a href="gallerij/stockfotos/boeken" class="catphotowrap"> <div class="catphotodiv"> <img class=&quo ...

The PHP file on my local WAMP server seems to be having trouble retrieving inputs from the HTML's GET or POST methods

<!DOCTYPE HTML> <html> <body> <form action="testrun.php" method="GET"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </bo ...

CSS: Struggling with Div Alignment

Here is a visual representation of the issue I am facing: View the screenshot of the rendered page here: http://cl.ly/image/0E2N1W1m420V/Image%202012-07-22%20at%203.25.44%20PM.png The first problem I have encountered is the excessive empty space between ...

Is it possible for me to use an image as a grid item?

I have a grid with 3 elements as shown below: Now, I am looking to replace the blue elements with images (they can be just placeholders). .grid-container { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(30em, auto); justi ...

Issues Persist with Making Ajax Calls to Webservice

I've been attempting to make a simple web API call from within an HTML page using ajax when a button is clicked. However, the call consistently fails. Oddly, the issue seems to only arise with the ajax call triggered by the button click, as the loadin ...

The code `$(body).css({'background-image':'url'}) is not functioning properly

Is it safe to assume that the .css() method cannot be applied to the body tag? Since it seems to work fine when used on $("#div")... ...

Navigate within the div by scrolling in increments of 100%

I am facing an issue with a div that contains multiple children set to 100% height. My goal is to scroll exactly the height of one child (which is also 100%) on each scroll. However, I am struggling to prevent scrolling multiple steps at a time. I have tri ...

Neglecting Min within the <input> field

I am facing a challenge with knockout.js in an ASP.NET application where I need to restrict users from entering negative numbers in a specific input field. The code snippet that is causing the issue is: <input type="number" class="form-control" data-bi ...

Exploring the contrast between a hidden element and an element positioned outside the viewport through Selenium testing

When a selenium element is disabled by the ng-show attribute being false, it will have the values Displayed=false and Enabled=true. However, if a selenium element is enabled with the ng-show attribute set to true but is out of the viewport, it will also ha ...

Utilizing Google Maps API version 3 to display various groups of markers

I am encountering an issue while trying to plot fixed markers and a user position marker on a Google Map. I want to use different images for these markers, but something strange is happening. When the page loads, all fixed markers show up correctly initial ...

No animated scrolling occurring

I have been struggling with this problem for a while now and despite having gone through 100 questions, I still can't find a solution as to why my code snippet is failing. Here is the jQuery code I am using: $("#readmore").click(function(event){ ...

Is it possible for me to create a variable that is assigned the width of the page as its value?

As I work on building a website for my company, I encountered an issue where certain divs overlap when the page is resized smaller. I am looking for a solution to dynamically adjust the CSS using JavaScript based on the width of the page. Despite attempti ...

I am in search of a clean and efficient method to modify the class of a link that triggers an HTMX request in Django. Perhaps something like "auto-refresh" or a similar solution would be ideal

I've encountered an issue with HTMX in Django. The page consists of two main components: a list of categories and the content that is displayed when a category is clicked. Initially, everything was working smoothly with standard htmx functionality. H ...

The background image doesn't extend to the bottom of the page due to the inability to utilize background-attachment

Currently, I am working on a project that requires a background image to cover the entire page. Unfortunately, using "background-attachment: cover" is not an option due to the need for compatibility with iOS, which does not support this property. .sky-b ...

Ways to focus on a specific div using JavaScript

I am attempting to create a 'snow' effect on the background of a particular div with a red border. Here is the code, but you can also view it here: <!-- language: lang-js --> var width = getWidth(); var height = getH ...

Identifying when floats exceed their limits

Is there a way to identify overflow on floating elements? It's important to note the difference between setting overflow to visible or hidden. overflow: visible; overflow: hidden; Do all floated elements inherently contain overflow? Why is it chal ...