簡體   English   中英

如何使下拉菜單水平

[英]how to make a drop down menu horizontal

我不確定這是否可行,但是我有一個名為“水果”的按鈕。 當我單擊它時,四個水果按鈕垂直向下顯示,但是我希望它們水平顯示嗎?

關於如何執行此操作的任何想法或提示?

請不要說“自己嘗試一下,不是在這里為您做這件事”。我一直以來都很無知。 我所尋找的只是一個提示,不希望任何人為我編碼。 謝謝 :)

HTML

<div id="myNav" class="overlay">
        <!-- Button to close the overlay navigation -->
        <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
        <!-- Overlay content -->
        <div class="overlay-content"> 
            <button class="dropbtn btn-circle overlay-icon" onclick='myFunction()'>Fruits</button>
            <div id="myDropdown" class="dropdown-content">
                <div class="row">
                    <div class="col-xs-12">
                        <button class="dropbtn btn-circle overlay-icon">Apple</button>
                        <button class="dropbtn btn-circle overlay-icon">Banana</button>
                        <button class="dropbtn btn-circle overlay-icon">Orange</button>
                        <button class="dropbtn btn-circle overlay-icon">Pear</button>
                    </div>
                </div>
            </div>

        </div>
    </div>

JS

 <script>
    /* 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 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');
          }
        }
      }
    }
    </script>

CSS

.overlay-icon { 
  float: center;
  width: 120px;
  height: 120px;
  text-align: center;
  padding: 600px 0;
  font-size: 12px;
  line-height: 1.428571429;
  border-radius: 36px;
  margin-left: 660px;
  margin-bottom: 20px;
}

.dropbtn:hover, .dropbtn:focus {
    background-color: #3e8e41;
}

.dropdown-content {
    display: none;
    position: relative;
    min-width: 10px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    font-size: 10px;  
    margin-left: 0px;
}

.dropdown-content dropbtn {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 10px;
}

我認為您需要將按鈕顯示為嵌入式塊。 這是CSS代碼:

.dropdown-content dropbtn {
  display: inline-block;
}

在您的CSS中更改,我刪除了margin-left並將padding600px 0更改為60px 0 600px 0

CSS:

.overlay-icon { 
  float: center;
  width: 120px;
  height: 120px;
  text-align: center;
  padding: 60px 0;
  font-size: 12px;
  line-height: 1.428571429;
  border-radius: 36px;
  margin-bottom: 20px;
}

.show {
   display: initial;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM