簡體   English   中英

如何設計具有下拉效果的下拉菜單?

[英]How can I design a dropdown menu with a draw-down effect?

我正在嘗試使用動畫制作下拉菜單。

到目前為止,我完成了以下示例中的常見下拉列表。

 input { display: none; } label { cursor: pointer; display: inline-block; padding: 10px 20px; border: 1px solid; border-radius: 4px; background: transparent; color: #000; z-index: 100; } .menu { -webkit-transition: all .3s ease; height: 0; overflow: hidden; width: 200px; background: red; height: 100px; z-index: -1; /* transform: translateY(-100%); */ /* I want it drawn down behind the button */ } input:checked+.menu { transform: translateY(50%); } 
 <label for="check">Click me</label> <input id="check" type="checkbox"> <div class="menu"> <p>I am dropdown menu</p> </div> 

但是,我的目的是設計一個可以向后滑動(下拉)的菜單

按鈕。 我已經將z-index設置為這些元素,但是沒有用。

另外,我無法將背景顏色設置為切換按鈕,我需要保持背景透明。

有什么建議么?

檢查以下css的更改,使菜單元素變為絕對且頂部填充

 input { display: none; } label { cursor: pointer; display: inline-block; padding: 10px 20px; border: 1px solid; border-radius: 4px; background: transparent; color: #000; z-index: 100; } .menu { -webkit-transition: all .3s ease; height: 0; overflow: hidden; width: 200px; background: #ffffff; height: 100px; z-index: -1; position:absolute; padding-top:35px; border:1px solid #000000; border-radius: 4px; } input:checked+.menu { transform: translateY(-40px); } 
 <label for="check">Click me</label> <input id="check" type="checkbox"> <div class="menu"> <p>I am dropdown menu</p> </div> 

暫無
暫無

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

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