简体   繁体   English

如何设计具有下拉效果的下拉菜单?

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

I am trying to do a dropdown menu with animation. 我正在尝试使用动画制作下拉菜单。

So far I finished a common dropdown like below example. 到目前为止,我完成了以下示例中的常见下拉列表。

 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> 

My purpose, however, is to design a menu that can slide down (draw down) behind 但是,我的目的是设计一个可以向后滑动(下拉)的菜单

the button. 按钮。 I had set the z-index to those elements but not works. 我已经将z-index设置为这些元素,但是没有用。

Also, I cannot set the background color to the toggle button, I need to keep it transparent. 另外,我无法将背景颜色设置为切换按钮,我需要保持背景透明。

Any suggestions? 有什么建议么?

Check below changes of css making menu element absolute and padding of top 检查以下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