2

我有一个按钮用于显示下拉 div。可以单击按钮填充和文本以显示下拉 div。无法单击非常小的材料“字体图标”以显示下拉 div。我如何确保您可以单击按钮内的任意位置(包括直接单击 Material 图标)以显示下拉 div。

这是一个链接,向您展示我所做的事情。

/* When the user clicks on the button, 
toggle between hiding and showing the dropdown content */
function myFunction() {
    document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {

    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}













// Hide Header on on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('header').outerHeight();

$(window).scroll(function(event){
    didScroll = true;
});

setInterval(function() {
    if (didScroll) {
        hasScrolled();
        didScroll = false;
    }
}, 250);

function hasScrolled() {
    var st = $(this).scrollTop();
    
    // Make sure they scroll more than delta
    if(Math.abs(lastScrollTop - st) <= delta)
        return;
    
    // If they scrolled down and are past the navbar, add class .nav-up.
    // This is necessary so you never see what is "behind" the navbar.
    if (st > lastScrollTop && st > navbarHeight){
        // Scroll Down
        $('header').removeClass('nav-down').addClass('nav-up');
    } else {
        // Scroll Up
        if(st + $(window).height() < $(document).height()) {
            $('header').removeClass('nav-up').addClass('nav-down');
        }
    }
    
    lastScrollTop = st;
}
body {
  margin: 0;
  color: #333;
  overflow-x: hidden;
  padding-top: 80px;
}


:root{
    var-MainColor: #4C00F9;
    --main-color: #4C00F9;
}






header {
    background: #f5b335;
    height: 40px;
    position: fixed;
    top: 0;
    transition: top 0.2s ease-in-out;
    width: 100%;
}

.nav-up {
    top: -64px;
}





#navWrapper {
  padding: 0px;
  border-bottom: 1px solid #eee;
  font-size: 13px;
  font-family: Sans-Serif;
  width: 100%;
  background-color: #fff;
  z-index: 1000;
  height: 64px;
}


#navLeft {
  float: left;
}

#navRight {
  float: right;
}




/* Dropdown Button */
.dropbtn {
    background-color: transparent;
    color: var(--main-color);
    padding: 24px;
    font-size: 13px;
    border: none;
    cursor: pointer;
}

/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
    background-color: var(--main-color);
  color: #fff;
  outline: none;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
    position: relative;
    display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
    display: none;
    position: absolute;
  margin-left: 10px;
  margin-right: 2%;
  margin-top: -8px;
  border-radius: 2px;
    background-color: #fff;
    min-width: 260px;
  border: 0px solid #eee;
    box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.3);
    z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
    color: var(--main-color);
    padding: 24px;
    text-decoration: none;
    display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #fdfdfd;}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}



















.material-icons.md-01 { font-size: 13px; vertical-align: middle; margin-top: -3px;}
.material-icons.md-02 { font-size: 24px; vertical-align: middle; margin-top: -5px; color: red;}
.material-icons.md-03 { font-size: 24px; vertical-align: middle; margin-top: -5px; color: #40FA35;}
.material-icons.md-04 { font-size: 21px; vertical-align: middle; margin-top: -1px;}
.material-icons.md-05 { font-size: 16px; vertical-align: middle; margin-top: -1px;margin-right: 15px;}

#main {
  margin-top: 50px;
  position: absolute;
}

section {
  width: 100%;
  border-bottom: 1px solid #eee;
  padding: 50px 0px;
}

#sectionInnerText {
  max-width: 700px;
  padding: 0px 100px;
  
}

#sectionInnerImage {
  max-width: 1000px;
  padding: 0px 100px;
}

#sectionInnerImage-rowWrapper {
  padding: 0px 100px;
}

#sectionInnerImage-3row {
  width: 31%;
  max-width: 400px;
  display: inline-block;
  margin-right: 1vw;
}

#sectionInnerImage-2row {
  width: 48%;
  max-width: 1000px;
  display: inline-block;
  margin-right: 1vw;
}



h1 {
  font-size: 36px;
  margin-bottom: 30px;
  font-weight: 700;
  font-family: Sans-Serif;
}

h2 {
  font-size: 22px;
  font-family: Sans-Serif;
  font-weight: 700;
  margin-top: 15px;
}

h3 {
  font-size: 13px;
  font-family: Sans-Serif;
  font-weight: normal;
  margin-bottom: 30px;
}

h4 {
  font-size: 17px;
  font-family: Sans-Serif;
  font-weight: 700;
  margin-top: 5px;
  margin-bottom: 0;
  display: inline-block;
}

p {
  font-size: 19px;
  line-height: 180%;
  font-family: Georgia, Cambria, "Times New Roman", Times, serif;
  font-weight: normal;
  margin: 15px 0;
}


a.one {
  display: block;
  color: #fff;
  background-color: var(--main-color);
  padding: 16px;
  text-decoration: none;
  text-align: center;
  border-radius: 3px;
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  max-width: 350px;
}

a.one:hover {
  background: #4C03F1;
}

a.one:active {
  background-color: var(--main-color);
}








@media only screen and (min-width: 1080px) {
    section {
    min-height: 30vh;
  }
  
}







@media only screen and (max-width: 1080px) {
  html, body {
  margin: 0;
  color: #333;
  overflow-x: hidden;
}
  section {
    width: 100%;
    border-bottom: 1px solid #eee;
    padding: 0px;
  }
  #sectionInnerText {
    padding: 2vh 5vw;
  }

  #sectionInnerImage {
    padding: 0 5vw;
  }
  
  #sectionInnerImage-rowWrapper {
  padding: 0 5vw;
}
  
  #sectionInnerImage-3row {
    width: 100%;
max-width: 1000px;
}

#sectionInnerImage-2row {
  width: 100%;
  max-width: 1000px;
}
  

  p {
    font-size: 21px;
  }
  
  ul li {
  font-size: 21px;
}
  
  a.one, a.two, a.three, a.four {
    display: block;
    margin-bottom: 25px;
    max-width: 100%;
    max-width: 450px;
  }
  
  .dropdown-content {
    width: 100vw;
    margin: 0;
    margin-top: -6px;
    background-color: #fff;
    min-width: 260px;
  border: 0px solid #eee;
    border-top: 1px solid #eee;
    border-bottom: 0;
    z-index: 1;
    box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.12);
    
    
  }
  
  .dropdown-content a{
    border-bottom: 1px solid #f4f4f4;
    
  }
  
  
  
  
}
<head>

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
</head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header class="nav-down">
<div id="navWrapper">
  <div id="navLeft">
  <div class="dropdown">
  <button onclick="myFunction()" class="dropbtn">Menu <i class="material-icons md-01">keyboard_arrow_down</i></button>
  <div id="myDropdown" class="dropdown-content">
    <a href="https://s.codepen.io/db13/debug/28af156fd624af1b7dc70adb3350030d"><i class="material-icons md-05">home</i> Home & Projects List</a>
    <a href="https://s.codepen.io/db13/debug/ca9b2e128f4fb8accf195c3fbe2e6868"><i class="material-icons md-05">dashboard</i> Project 01</a>
    <a href="https://s.codepen.io/db13/debug/ca9b2e128f4fb8accf195c3fbe2e6868"><i class="material-icons md-05">dashboard</i> Project 02</a>
    <a href="https://s.codepen.io/db13/debug/ca9b2e128f4fb8accf195c3fbe2e6868"><i class="material-icons md-05">dashboard</i> Project 03</a>
    <a href="https://s.codepen.io/db13/debug/f14ac89d2cebafdf088d1d6043c9507c" style="border-left:5px solid var(--main-color);"><i class="material-icons md-05">account_circle</i> Info & Contact</a>
    <a href="#"><i class="material-icons md-05">picture_as_pdf</i> View & Download Resume</a>
  </div>
</div>
    </div>
</div>
</header>

4

0 回答 0