css菜单下拉菜单_CSS下拉指南:如何在CSS中创建下拉菜单

css菜单下拉菜单

什么是下拉菜单? (What are Dropdowns?)

Dropdown menus are used in CSS to hide a predefined list within a button.

CSS中使用下拉菜单来隐藏按钮内的预定义列表。

Examples:

例子:

<div class="dropdown">
  <button class="dropbtn">Name</button>
  <div class="dropdownContent">
    <a href="#">One</a>
    <a href="#">Two</a>
    <a href="#">Three</a>
  </div>
</div>

Then you should customise the classes in CSS like this:

然后,您应该像这样自定义CSS中的类:

.dropdown {
  position: relative;
  display: inline-block;
}

.dropbtn {
  background-color: red;
  padding: 10px;
}

.dropdown-content {
  display: none;
  position: absolute;
}

.dropdown:hover .dropdown-content {
  display:block;
}

You need the separate div classes to create the button, and another div to separate the list of what the button contains.

您需要单独的div类来创建按钮,并且需要另一个div来分离按钮所包含内容的列表。

一个例子 (An Example)

<div id="container">
  
        <div id="myNav1" class="overlay">
  
            <div class="overlay-content" id="myNav1-content">
  
                <div>
                    <a href="#" id="list1_obj1" class="list1" >Content 1</a>
                </div>
                <div>
                    <a href="#" id="list1_obj2" class="list1" >Content 2</a>
                </div>
  
            </div>
  
         </div>
  
         <div id="myNav2" class="overlay">
  
             <a href="javascript:void(10)" class="closebtn" onclick="closeNav()">&times</a>
            <div class="overlay-content" id="myNav2-content">
  
                <div>
                    <a href="#" id="list2_obj1" class="list2" >Content 3</a>
                </div>
                <div>
                   <a href="#" id="list2_obj2" class="list2" >Content 4</a>
                </div>
                <div>
                  <a href="#" id="list2_obj3" class="list2" >Content 5</a>
                </div>
  
            </div>
  
         </div>
  
 </div>
#myNav1 {
    height: 0;
    width: 50%;
    position: fixed;
    z-index: 6;
    top: 0;
    left: 0;
    background-color: #ffff;
    overflow: hidden;
    transition: 0.3s;
    opacity: 0.85;
}

#myNav2 {
    height: 0;
    width: 50%;
    position: fixed;
    z-index: 6;
    bottom: 0;
    right: 0;
    background-color: #ffff;
    overflow: hidden;
    transition: 0.3s;
    opacity: 0.85;
}

.overlay-content {
    position: relative;
    width: 100%;
    text-align: center;
    margin-top: 30px;
}

#myNav1-content{
    top: 12%;
    left: 5%;
    display: none;
}

#myNav2-content{
    top: 12%;
    right: 10%;
    display: none;   
}

有关CSS下拉菜单的更多信息: (More info on CSS dropdowns:)

翻译自: https://www.freecodecamp.org/news/css-dropdown-guide-how-to-make-a-dropdown-menu-in-css/

css菜单下拉菜单

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值