我是靠谱客的博主 高挑雪糕,这篇文章主要介绍纯css下拉菜单 无需js,现在分享给大家,希望可以做个参考。

再来个今天某人说过的例子:纯css下拉菜单:
效果图

这个的实现很简单,主要是:hover和过渡属性transition的使用。

代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>css</title> <style> *{ margin: 0; padding:0; font-size: 16px; font-family: "微软雅黑"; } #container{ width: 100px; margin: 0 auto; text-align: center; position: relative; } #container ul{ list-style: none; } #container span{ display: inline-block; width: 100px; height: 30px; line-height: 30px; cursor: pointer; } #container ul{ height: 0; width: 100px; overflow: hidden; transition: all 1s; position: absolute; top: 30px; left: 0px; } #container:hover ul{ height: 330px; } #container ul li{ background: #eee; margin-top: 3px; cursor: pointer; height: 30px; line-height: 30px; } </style> </head> <body> <div id="container"> <span>移动</span> <ul> <li>这里有1</li> <li>这里有2</li> <li>这里有3</li> <li>这里有4</li> <li>这里有5</li> <li>这里有6</li> <li>这里有7</li> <li>这里有8</li> <li>这里有9</li> <li>这里有10</li> </ul> </div> </body> </html>

因为ul是个伸缩对象,所以要让它脱离文档流,不是在实用时会影响到布局,给它一个绝对定位即可。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

最后

以上就是高挑雪糕最近收集整理的关于纯css下拉菜单 无需js的全部内容,更多相关纯css下拉菜单内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(147)

评论列表共有 0 条评论

立即
投稿
返回
顶部