css菜单下拉菜单

CSS | 创建下拉菜单 (CSS | Creating Dropdown)

Trivia:

琐事:

We know the importance of navigation bar on our webpage, we know the importance of a list of items too on our webpage but what is the importance of dropdown in web pages?

我们知道网页上导航栏的重要性,也知道我们网页上项目列表的重要性,但是网页下拉菜单的重要性是什么?

Well, there are too many to mention but let's discuss a few of them.

好吧,有太多事情要提,但让我们讨论其中的一些。

First, the dropdown is a packed arrangement of a list of items which saves space for our website.

首先, 下拉列表是项目列表的紧凑排列,可以节省我们网站的空间。

The dropdown is a stylish way to display your options on the web page as it also increases the curiosity of the users to go and click on the dropdown option.

下拉菜单是一种在网页上显示您的选项的时尚方式,因为它还增加了用户单击该下拉菜单选项的好奇心。

Therefore, the dropdown option is very essential while creating and designing a web page.

因此,在创建和设计网页时, 下拉选项非常重要。

However one must be very careful while creating a dropdown option as it is a common tendency to mix up the options when someone is new and is learning CSS.

但是,在创建下拉选项时必须非常小心,因为在新手学习CSS时,混合选项是一种常见的趋势。

The prime tip to create a dropdown option is that one should be clear in what all options he/she may require to display on the web page.

创建下拉选项的主要提示是,应该明确他/她可能需要在网页上显示的所有选项。

Many users do not tend to go through the entire web page rather they always look for a dropdown option that would contain the links of the shortcuts.

许多用户并不倾向于浏览整个网页,而是总是寻找包含快捷方式链接的下拉选项。

There to create a dropdown with quick links as menu items are good practice and thus happy users!

在那里创建带有快速链接的下拉菜单,因为菜单项是一种很好的习惯,因此用户满意!

Now let's talk about how to create a dropdown option using CSS,

现在让我们谈谈如何使用CSS创建下拉菜单选项,

基本下拉 (Basic DropDown)

For HTML:

对于HTML:

  • Step 1: Create a button or a similar option that would open your dropdown.

    第1步 :创建一个按钮或类似选项,以打开您的下拉菜单。

  • Step 2: Use a container element for e.g. <div> to help you create a dropdown option and then you can add anything inside it whatever you want to display to the users.

    第2步 :使用一个容器元素(例如<div>)来帮助您创建一个下拉选项,然后您可以在其中添加任何想要显示给用户的内容。

  • Step 3: Wrap the <div> element around the elements which would help in positioning the dropdown content correctly with the CSS.

    步骤3 :将<div>元素环绕在元素周围,这将有助于使用CSS正确放置下拉内容。

For CSS:

对于CSS:

The dropdown class uses various properties. One of them is position:relative which would be needed in placing the dropdown content right below the dropdown option.

下拉类使用各种属性。 其中之一是position:relative ,将下拉菜单内容放置在下拉选项正下方时需要使用。

  • Step 4: The dropdown contains the actual dropdown content which would be displayed only when the user hovers over it.

    步骤4 :下拉菜单包含实际的下拉菜单内容,仅当用户将鼠标悬停在其上时才会显示。

  • Step 5: If you want the width of your dropdown content to be as equally wide as the dropdown button then you must change the width to 100% and also enable overflow:auto so that your content will be able to scroll on small screens.

    第5步 :如果您希望下拉内容的宽度与下拉按钮的宽度相同 ,则必须将宽度更改为100% ,还必须启用overflow:auto,这样您的内容才能在小屏幕上滚动。

You can always change the alignment of your dropdown by using the right-aligned dropdown. To make your content go from right to left you must set right:0.

您始终可以使用right-aligned dropdown更改下拉菜单的对齐方式 。 要使内容从右到左,您必须设置right:0 。

Syntax:

句法:

.dropdown-content {right: 0;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {background-color: #3eff;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {position: relative;
display: inline-block;
}
.dropdown-content {display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #3eff;
}
.dropdown:hover .dropdown-content {display: block;
}
.dropdown:hover .dropbtn {background-color: #3eff;
}
</style>
</head>
<body>
<div class="dropdown" style="float:left;">
<button class="dropbtn">Left</button>
<div class="dropdown-content" style="left:0;">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</body>
</html>

Output

输出量

In the above example, styles have been set to the dropdown property.

在上面的示例中,样式已设置为dropdown属性

翻译自: https://www.includehelp.com/code-snippets/creating-dropdown-in-css.aspx

css菜单下拉菜单

css菜单下拉菜单_在CSS中创建下拉菜单相关推荐

  1. html 下拉框设置名称,html下拉菜单怎么做?高手教你如何在HTML和CSS中创建下拉菜单...

    html下拉菜单怎么做?html下拉菜单代码是什么?这些对于刚刚入门的新手,还不是很明白,下面高手教你如何在HTML和CSS中创建下拉菜单? 很多人都会遇到将鼠标悬停在导航上,会出现下拉菜单; 一般出 ...

  2. swift 自定义滑动视图_在Swift中创建一个向上滑动菜单视图(以编程方式)

    swift 自定义滑动视图 This is a quick tutorial on how to create a slide-up menu view in iOS 这是有关如何在iOS中创建向上滑 ...

  3. python中的for in循环有什么意思_for _ in xxx中的下划线_是什么意思?

    for _ in list中的下划线_只是一个临时的循环变量, 因为_是合法的变量名 for _ in [1, 2, 3]:print(_) li = [[0, 1] for _ in range(3 ...

  4. 怎么在html5中制作下拉导航栏,在PPT中制作下拉式导航菜单效果的方法

    为了提高PPT演示文稿的观赏性,用户可能希望在PPT幻灯片中添加下拉式导航菜单效果,通过该导航菜单在不同幻灯片间进行导航(如图1所示),制作下拉式导航菜单的具体操作步骤如下. 图1 下拉式导航菜单 ( ...

  5. css颜色rgba代码对照表_改善 CSS 的 10 个最佳实践

       戳蓝字「前端技术优选」关注我们哦! CSS 看起来是一种非常直接且不易犯错的语言.只需要添加规则以对网站进行样式设置就可以了,对吗?对于只需要几个 CSS 文件的小型站点,可能是这种情况.但是在 ...

  6. css grid随页面大小_前端开发中各种设置CSS间距的优点缺点及实例「实践」

    前言 如果两个或多个元素很接近,那么用户就会认为它们以某种方式属于彼此.当对多个设计元素进行分组时,用户可以根据它们之间的空间大小来决定它们之间的关系.没有间距,用户将很难浏览页面并知道哪些内容相关而 ...

  7. 5种css隐藏元素的方法_在CSS中隐藏元素的10种方法

    5种css隐藏元素的方法 There are multiple ways to hide an element in CSS, but they differ in the way they affe ...

  8. layui 数据表格下拉框_LayUi数据表格中嵌套下拉框

    layui嵌套下拉框实用方法(附效果图) 在做项目时遇到一个问题,在layui 的数据表格table里面如何做一个下拉框呢?效果图如下: 这样的效果想必是最理想的了 思路分析: 我们可以通过layui ...

  9. scala中何时使用下划线_在Scala中使用下划线

    scala中何时使用下划线 Underscore (_) character is reserved in Scala and has multiple usages in the programmi ...

最新文章

  1. (C++)1029 旧键盘
  2. Ubuntu 16.04 LTS界面美化
  3. kubeadm常见报错和解决方法
  4. 做301定向跳转对网站优化有什么帮助?
  5. TM、XWT和Wazaabi
  6. 《微机原理及接口技术》第08章在线测试
  7. Linux怎么调oracle存储,Linux 环境下Oracle安装与调试(四)之视图、存储过程
  8. Memcache持久性分布式数据MemcacheDB
  9. Power BI Embedded 开发国内版-21V-版本实测
  10. 解决Ubuntu Chrome浏览器很卡不响应的问题
  11. 展开字符串(dfs)
  12. 学了python能干啥举例-Python主要用来做什么?
  13. Java机器学习开发库
  14. Android studio 真机调试出现sdk版本不匹配问题
  15. 1. 英语邮件中经常用到的单句 (每次10句)
  16. VHDL实现交通灯程序
  17. 苹果邮箱格式_3个小工具,让PDF格式不仅能编辑还能转成word 、execl、 ppt
  18. 信号与系统实验二 信号运算的MATLAB 实验
  19. 网站安全检测漏洞扫描系统邮件安全
  20. 路由器、交换机设备管理

热门文章

  1. 关闭Android电池温度告警框,android电源信息查看(电量、温度、电压)实例代码
  2. linux没有root密码xshell,LINUX终端免密登陆(以Xshell为例)
  3. 课时3.浏览器访问网页原理(理解)
  4. 自定义checkbox样式
  5. html/css学习笔记(一)
  6. java中值传递和引用传递
  7. 汇编小记16/3/27
  8. Canvas动画 位图缓存提高效率和对应的内存问题
  9. fis 详细介绍(mac版) - 12-26没有弄完 - 暂停
  10. Response.Write具体介绍