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

`Switching the selection in ng-selected`

I am having trouble toggling ng-selected options in Angular. I have tried the following approach: <select ng-model="datacut.ages" multiple> <option value="" disabled="disabled">Please Select</option> <option value="0-15" ng-clic ...

Incorporating Bootstrap content directories into ASP.NET website projects

I've been experimenting with Bootstrap for website design, but I'm facing an issue with adding files to my project. When creating a project in Visual Studio 2015 using File/New/Web Site..., I'm able to simply Copy/Paste the css, fonts, js fo ...

Utilize Vue.js functions within data through the Vue.js context

I'm trying to incorporate a function as a data property. While it works for the 'works' data property, I need access to the this context within the function in order to calculate values from the shoppingCart property. Is there a way to achie ...

Utilizing Angular JS to Manage Controller Events

I am currently working on an application that requires saving a large amount of data in cascade, similar to a typical master-detail view. Within this view, there is a "Save All" Button which saves each row in an iteration. This process triggers jQuery cus ...

Refining an array data table within a nested component

Transitioning my old PHP/jquery single-page applications to VueJS/Webpack has been a journey I'm undertaking to familiarize myself with the latter technology. It involves converting a simple table that pulls data from a JSON API and incorporates filte ...

The reset function for the selector is failing to properly reset the data within the table

I need help with a selector that has multiple options and a reset button. When the reset button is clicked, it should reset the selector back to the first option. Although the selector resets as expected when the button is clicked, the data in the table r ...

Updating a List Conditionally in React

Hello there! I am relatively new to the world of React and currently trying to grasp the concept of modifying elements within a list. Below, you'll find a straightforward example that illustrates my current dilemma. const numbers = [1, 2, 3, 4, 5]; / ...

Spacing Problem with Title Tooltips

After using the padEnd method to ensure equal spacing for the string and binding in the title, I noticed that the console displayed the string perfectly aligned with spaces, but the binded title appeared different. Is it possible for the title to support s ...

How can one efficiently update numerous data properties in a Vue.js application?

My information is as follows: data() { return { monday_start: '', monday_end: '', tuesday_start: '', tuesday_end: '', wednesday_start: '', ...

Leveraging ajax data to enhance visual representation in graphs

Having trouble fetching data from a database to display it in a graph.js graph. I've attempted setting a timeout for the async callback from Ajax, but nothing seems to be working. Any suggestions on how to make this work would be greatly appreciated! ...

Attributes of an object are altered upon its return from a Jquery function

After examining the following code snippet: index.html var jsonOut = $.getJSON("graph.json", function (jsonIn) { console.log(jsonIn); return jsonIn; }); console.log(jsonOut); The graph.json file contains a lengthy JSON fo ...

Efficient ways to clear all input fields within a React div component

import "./App.css"; import { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { addUser} from "./features/Users"; function App() { const dispatch = useDispatch(); const use ...

What is the best way to seamlessly transition layers from one location to another as the mouse exits and re-enters the window?

I have been working on refining a parallax effect to achieve a seamless transition between two positions based on where the mouse exits and enters the window. In the JSFiddle example provided, there is a slight 'pop' that I am looking to replace ...

Is it possible to use JavaScript for detecting third-party videos?

I'm currently developing an HTML5 video player that also has a fallback to flash. One of the challenges I am facing is that the video content is being provided by various third-party sources. It seems that some of these third parties serve videos bas ...

Ways to create an object based on another object

Currently, I am teaching myself Javascript. My focus is on working with Vuejs and express for a CRUD App. In one of my components, I retrieve data from my backend using the API: localhost:3000/api/transport. The response contains all objects from the data ...

npm ERR! Your operating system has denied the operation

When attempting to install create-react-app globally using 'npm install -g create-react-app', an error occurred due to insufficient write access to the /usr/local/lib/node_modules directory. The error message displayed was as follows ...

Send the values of the form variables as arguments

I am trying to integrate a webform (shown below) with a function that passes form variables. Once the user clicks submit, I want the username and password to be passed into a website login function: $.ajax( { url: "http://microsubs.risk.ne ...

Activating two buttons in jquery will trigger this action

I am currently working on developing a filter button that will perform different actions based on which buttons are pressed. Pressing button1 will trigger one action, while pressing button2 will trigger another action. If button1 is pressed first, followe ...

Monitoring and recording the current line number during evaluation

Recently, I've been experimenting with eval to modify a $scope object named variables. This is the watcher I'm using: $scope.$watch(function () { return $scope.variables; }, function (variables) { console.log('changed!'); }, true) ...

What is the best way to calculate the number of days between today's date and the end of the current month using Moment.js?

Here's the current code snippet I am working with: const moment = require('moment') const m = moment const currDay = m().format('D') const dayOfWeek = m().format('dddd') const daysInMonth = m().daysInM ...