Dropdown Menu for Materialize not working

Spencer McLeod picture Spencer McLeod · May 22, 2018 · Viewed 12.8k times · Source

So I've followed two different ways of creating a dropdown menu with Materialize CSS (using their documentation: https://materializecss.com/navbar.html & https://materializecss.com/dropdown.html) and I can't get either to work. I've also cruised through here and found similar problems but none seemed to quite solve my issue so here it goes...

I'm trying to make a mobile menu for a webapp using Meteor & Materialize. Here's some of my code:

<ul id="dropdown" class="dropdown-content">
    <li><a href="#">EMPOWER YOUR BUSINESS!</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">Contact</a></li>
</ul>
<ul class="hide-on-med-and-up">
    <li><a class="dropdown-trigger" data-target="dropdown">
        <i class="material-icons">menu</i></a>
    </li>
</ul>
<script>
    $(document).ready(function(){
        $('.modal').modal();
        $('.dropdown-trigger').dropdown();
    });
</script>

I have included <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> in the head and the jQuery call in the code above is right before the closing body tag.

Any help would be much appreciated.

Answer

user8477089 picture user8477089 · May 23, 2018

$(document).ready(function(){
   $('.modal').modal();
   $('.dropdown-trigger').dropdown();
});
.dropdown-content{
   width: max-content !important;
   height:auto !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">

    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<ul id="dropdown" class="dropdown-content">
    <li><a href="#">EMPOWER YOUR BUSINESS!</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">Contact</a></li>
</ul>
<ul class="dds">
    <li><a class="dropdown-trigger" data-target="dropdown">
        Dropdown <i class="material-icons">arrow_drop_down</i></a>
    </li>
</ul>