Create a stylish navigation dropdown with MaterializeCSS

Incorporating the materializecss dropdown menu feature, I encountered an issue where only two out of four dropdown menu items were visible. Here is the HTML code snippet in question:

<nav class="white blue-text">
  <div class="navbar-wrapper container">
    <a href="#" data-activates="mobile-menu" class="button-collapse indigo-text"><i class="material-icons">menu</i></a>
    <a href="#" class="brand-logo left">
      <img src="images/logo.png" class="top-logo">
    </a>

    <ul class="hide-on-med-and-down right">
      <li class="waves-effect waves-light"><a href="index.html">Home</a>
      </li>
      <li class="waves-effect waves-light"><a href="about.html">About Us</a>
      </li>
      <li class="waves-effect waves-light"><a class="dropdown-button" href="#!" data-activates="dropdown1" href="javascript:void(0)">Gallery</a>
      </li>
      <ul id='dropdown1' class='dropdown-content'>
        <li><a href="#!">Videos</a>
        </li>
        <li><a href="#!">Publication</a>
        </li>
        <li><a href="#!">Interviews</a>
        </li>
        <li><a href="#!">Pictures</a>
        </li>
      </ul>
      <li class="waves-effect waves-light"><a href="javascript:void(0)">News</a>
      </li>
      <li class="waves-effect waves-light active"><a href="events.html">Events</a>
      </li>
      <li class="waves-effect waves-light"><a href="partners.html">Partners</a>
      </li>
      <li class="waves-effect waves-light"><a href="javascript:void(0)">Contact Us</a>
      </li>
    </ul>
    <ul class="side-nav" id="mobile-menu">
      <li class="waves-effect waves-light"><a href="index.html">Home</a>
      </li>
      <li class="waves-effect waves-light"><a href="about.html">About Us</a>
      </li>
      <li class="waves-effect waves-light"><a href="javascript:void(0)">Gallery</a>
      </li>
      <li class="waves-effect waves-light"><a href="javascript:void(0)">News</a>
      </li>
      <li class="waves-effect waves-light active"><a href="events.html">Events</a>
      </li>
      <li class="waves-effect waves-light"><a href="partners.html">Partners</a>
      </li>
      <li class="waves-effect waves-light"><a href="javascript:void(0)">Contact Us</a>
      </li>
    </ul>
  </div>
</nav>

My only modification to the nav in my CSS was as follows:

nav ul a {
  font-size: 1.1rem;
  color: #2196F3;
}
nav,
nav .nav-wrapper i,
nav a.button-collapse,
nav a.button-collapse i {
  height: 105px;
  line-height: 105px;
}

To see the issue for yourself, you can check the navigation bar on this site: Clicking on the Gallery option will showcase the problem mentioned above.

Answer №1

I have found the solution to what you were looking for! After some troubleshooting, I discovered a small issue that was causing your code to break. I simply removed the class="waves-effect waves-light" from the <li> tag of the dropdown.

Below is the working code along with all CDN files. Simply copy and paste the code into any file, save it with a .html extension, and run it directly.

Header Section

<!DOCTYPE HTML>
<html>
<head><title>
    </title>

    <!-- Font-Awesome CDN -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"></link>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css">


</head>

Next is the Body section with nav

<body>

    <nav class="white blue-text">
      <div class="navbar-wrapper container">
        <a href="#" data-activates="mobile-menu" class="button-collapse indigo-text"><i class="material-icons">menu</i></a>
        <a href="#" class="brand-logo left">
          <img src="images/logo.png" class="top-logo">
      </a>

      <ul class="hide-on-med-and-down right">
          <li><a href="index.html">Home</a>
          </li>
          <li><a href="about.html">About Us</a>
          </li>
          <li>
            <a class="dropdown-button" href="#!" data-activates="dropdown1" href="javascript:void(0)">Gallery</a>
          </li>
          <ul id='dropdown1' class='dropdown-content'>
            <li>
                <a href="#!">Videos</a>
            </li>
            <li>
                <a href="#!">Publication</a>
            </li>
            <li>
                <a href="#!">Interviews</a>
            </li>
            <li>
                <a href="#!">Pictures</a>
            </li>
        </ul>
        <li><a href="javascript:void(0)">News</a>
        </li>
        <li><a href="events.html">Events</a>
        </li>
        <li><a href="partners.html">Partners</a>
        </li>
        <li><a href="javascript:void(0)">Contact Us</a>
        </li>
    </ul>
    <ul class="side-nav" id="mobile-menu">
      <li><a href="index.html">Home</a>
      </li>
      <li><a href="about.html">About Us</a>
      </li>
      <li><a href="javascript:void(0)">Gallery</a>
      </li>
      <li><a href="news.html">News</a>
      </li>
      <li><a href="events.html">Events</a>
      </li>
      <li><a href="partners.html">Partners</a>
      </li>
      <li><a href="contact.html">Contact Us</a>
      </li>
  </ul>

Finally, the script and style sections along with the body end tag and footer

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
</body></html>

The styles for the navigation are the same as the ones you used. I haven't added them in the code, but you can add them before running the code.

I hope this helps! Best of luck with your project.

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

Encounter error message "Angular-CLI: Karma-Webpack fails due to 'file or directory not found'"

After initially starting with the classic Angular/systemjs setup for the Tour of Heroes, I transitioned to using angular-client. The application now performs well in both development and production modes, except for when I try to run tests using ng test. A ...

Is there a streamlined approach to signal a successful callback to $q.all without the need to define a $q.defer() variable?

Within my application, I have a mixture of synchronous and asynchronous methods. Here is an example of code from one of the controllers: $q.all([ asyncMethod1(), syncMethod1() ]) .then(function (results) { Even though I don't actually need t ...

When async/await is employed, the execution does not follow a specific order

I'm curious about the execution of async/await in JavaScript. Here are some example codes: async function firstMethod(){ new Promise((resolve, reject)) => { setTimeout(() => { resolve("test1"); }, 3000); }); } async ...

Is it possible to alter CSS attributes dynamically without setting a limit on the number of changes that can be made?

In my current project, I am looking to add a feature that allows users to choose the color scheme of the software. While the choices are currently limited, I plan to implement a color picker in the future to expand the options available. So far, I have ex ...

The Mean stack application is throwing an error message: "user.comparePassword is not

This section contains my user models in the file named "user.js". var mongoose = require('mongoose'); var bcrypt = require('bcryptjs'); let emailLengthChecker = (email) => { if (!email) { return false; } else { if (emai ...

jQuery draggable elements can be easily dropped onto droppable areas and sorted

I need help with arranging the words in the bottom tiles by sorting them from "Most Like Me" to "Least Like Me" droppable areas. Currently, I am able to drag and drop the words into different boxes, but it ends up stacking two draggable items on top of eac ...

Download personalized HTML design

Situation When exporting to HTML, the resulting code appears as follows: <html> <head> <title></title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style type="text/css" ...

The integration of Material-UI Autocomplete and TextField causes google autocomplete to activate

I am currently working on integrating the Autocomplete component into my project. However, I am facing an issue where the browser's autofill/autocomplete feature kicks in after some time. Is there a way to disable this behavior? ...

default selection in AngularJS select box determined by database ID

Here is the scenario: ... <select ng-model="customer" ng-options="c.name for c in customers"> <option value="">-- choose customer --</option> </select> .... In my controller: $scope.customers = [ {"id":4,"name":"aaaa", ...

Incorporate a SharpSpring form within a custom React component

Trying to integrate a Sharpspring form script into my React component (page.jsx). The form needs to be placed outside the <head></head> element and inside the <div> where I want to display it. The original HTML code for embedding the for ...

Troubleshooting problem with CSS alignment within Bootstrap framework

Having trouble with the alignment when using bootstrap CSS. My desired layout is as follows: Place name: dropdownbox Gender (radio-button)Male (radio-button)Female Amount Max: textbox Min: textbox Any advice on how to achieve this? ...

Adding labels to a JavaScript chart can be done by using the appropriate methods

https://i.stack.imgur.com/uEgZg.png https://i.stack.imgur.com/y6Jg2.png Hey there! I recently created a chart using the Victory.js framework (check out image 1) and now I'm looking to incorporate labels similar to the ones shown in the second image ab ...

Two distinct iterations of the identical jquery version sourced from external sources

NOTE: This situation involves having two copies of jQuery with the same version number but different libraries loaded by external sources. This is distinct from the issue of using multiple versions of jQuery on a single page, as discussed here: Can I use m ...

jquery allows you to toggle the visibility of content

There are two divs with a button positioned above them. Initially, only one div, the catalogusOrderBox, is visible. When the button named manualButton is clicked, it should display the manualOrderBox div while hiding the catalogusOrderBox div. The text on ...

Efficiently managing routes by segmenting them into distinct files

My Express app is structured in the standard Express 4 format, with dependencies at the top, followed by app configuration, routes, and finally the listen function. I'm currently working on organizing my routes into categorized files (e.g., routes/au ...

What is the method for incorporating an async middleware into a router route?

I am currently setting up routes for an express router in my project. I have a validator that deals with promises, requiring me to use await in the code. Here is how it looks: constructor() { this.router = express.Router(); this.router.use(express. ...

Is it possible to set up a server with 'app' as the designated request handler?

When working with NodeJS, server creation can be done simply by using: http.createServer(function(req,res) { /* header etc. */}); However, as I delved into using express, the server was automatically created for me. Moving on to learning about sockets, I ...

Validating uploaded files in Javascript and handling server upload operations

I'm having a small issue with a webpage I am creating. Essentially, I am looking to validate whether a user has selected a file and then upload it to the server. I understand this can be done using JavaScript: if(document.getElementById("uploadBox"). ...

Karma and RequireJS fetching files beyond the base URL

My goal is to set up automatic testing using karma with the following file structure: /assests /css /font /img /js /collection /lib /model /plugin /spec /view test-main.js main.js /templates index.html karma.conf.js In my ...

What could be causing the CastError: Cast to ObjectId failed in my code?

Whenever I try to access a specific route in my project, the following error is returned: Server running on PORT: 7000 /user/new CastError: Cast to ObjectId failed for value "favicon.ico" (type string) at path "_id" for model "User" at model.Query.exe ...