css菜单下拉菜单_在CSS中创建下拉菜单

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

输出量

dropdown menu using CSS | Example 1

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菜单下拉菜单

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377517.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++ 内存基本构件new/delete的意义、运用方式以及重载方式

目录一、对new的理解1、new做了什么2、new被编译器转为了什么3、operate_new源代码长啥样二、对delete的理解1、delete做了什么2、delete被编译器转为了什么3、operator delete源代码长啥样三、构造函数与析构函数的直接调用参考一、对new的理解 1、new做了什么 C告诉我们&am…

二、线性代数

一、张量 张量表示由一个数值组成的数组&#xff0c;这个数组可能有多个维度 import torchx torch.arange(15) x # tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])1&#xff0c;shape shape属性可以访问张量的形状 x.shape # torch.Size([15])2&a…

Wordpress prettyPhoto插件跨站脚本漏洞

漏洞名称&#xff1a;Wordpress prettyPhoto插件跨站脚本漏洞CNNVD编号&#xff1a;CNNVD-201311-413发布时间&#xff1a;2013-11-28更新时间&#xff1a;2013-11-28危害等级&#xff1a; 漏洞类型&#xff1a;跨站脚本威胁类型&#xff1a;远程CVE编号&#xff1a; 漏洞来源…

JavaScript学习笔记1

Netscape 公司 DOM模型&#xff0c;层(layer)-用ID标识。 HTML标记页面上的元素&#xff0c; <div id "mydiv">This is my div</div> CSS为这个页面元素定位 #mydiv{ position:absolute; left:320px; top:110px; } JavaScript 访问 (DOM模块不同&#x…

c# 中关键字_C#中的“使用”关键字

c# 中关键字Prerequisite: Namespace in C# 先决条件&#xff1a; C&#xff03;中的命名空间 If you want to include namespace in a program then we need to use using keyword. For example we use Console class which is defined in System namespace that’s why we n…

C++ 内存基本构件new [] /delete []的意义、内存泄漏原因、VC下cookie的基本布局

目录一、对new [] delete [] 的理解1、delete的[]遗漏会带来什么影响二、以示例探讨三、cookie的理解一、对new [] delete [] 的理解 new的对象是个array类型的。 Complex* pca new Complex[3]; //唤起三次ctor //无法借由参数给予初值 ... delete[] pca; //唤起3次dtor如下…

OpenJudge计算概论-找出第k大的数

/* 找出第k大的数 总时间限制: 1000ms 内存限制: 1000kB 描述 用户输入N和K&#xff0c;然后接着输入N个正整数&#xff08;无序的&#xff09;&#xff0c;程序在不对N个整数排序的情况下&#xff0c;找出第K大的数。注意&#xff0c;第K大的数意味着从大到小排在第K位的数。并…

01背包怎么不重复_带有重复物品的背包

01背包怎么不重复Problem statement: 问题陈述&#xff1a; Weights and values are given for n items along with the maximum capacity allowed W. What is the maximum value we can achieve if we can pick any weights, any number of times for the total allowed capa…

jQuery数组处理汇总

有段时间没写什么了, 打算把jquery中的比较常用的数组处理方法汇总一下 $.each(array, [callback])遍历,很常用 ?12345678var arr [javascript, php, java, c, c#, perl, vb, html, css, objective-c];$.each(arr, function(key, val) {// firebug consoleconsole.log(index …

C++ 内存基本构件 placement new

用法以及编译器解释 placement new 允许我们将object构建于已经分配的内存上。(所以此时必须有个指针指向已经分配好的内存) 没有所谓的placement delete &#xff0c;因为placement new根本没有分配内存. 也有种说法&#xff0c;是将placement new对应的内存释放掉的操作为pl…

二维数组for遍历

<?php$conarray(array(1,高某,A公司,北京市,010,abc),array(2,罗某,B公司,天津市,020,bcd),array(3,冯某,C公司,上海市,021,cdf),array(4,书某,D公司,重庆市,022,dfg));echo <table border"1" width"600" align"center">;echo <cap…

Xcode调试相关小结

一.设置NSZombieEnabled 使用NSZombieEnabled功能,当代码中访问已经释放了内存的地方,会给你下面这样的提示,而不仅仅是EXEC_BAD_ACCESS: 2008-10-03 18:10:39.933 HelloWorld[1026:20b] *** -[GSFont ascender]: message sent to deallocated instance 0x126550 如果要查看上面…

ONGC的完整形式是什么?

ONGC&#xff1a;石油天然气公司 (ONGC: Oil and Natural Gas Corporation) ONGC is an abbreviation of Oil and Natural Gas Corporation. It is an Indian multinational corporation that is one of the leading producers of crude oil and natural gas in India. Its hea…

C/C++代码优化方法

目录优化概述_O0优化_O1优化_O2优化_O3优化volatile关键字避免优化优化概述 如果将未经优化的C语言程序直接运行会发现运行效率较低&#xff0c;并且产生的代码较大&#xff0c;而通过优化可以较好地解决这些问题。 优化的作用是对循环进行化简&#xff0c;重新组织表达式和声…

大学生应当趁早谋划未来(二)--给表弟的建议

背景表弟&#xff0c;大四&#xff0c;湖北某二本院校&#xff0c;计算机相关专业。大学期间&#xff0c;对Java等编程没有兴趣&#xff0c;几乎没怎么学习。平时&#xff0c;课程比较多&#xff0c;每天6节左右。课外&#xff0c;自己去挣点生活费,父亲生病了。困境最近在找工…

UVa 490 - Rotating Sentences

把输入的字符顺时针旋转90度。 1 #include<stdio.h>2 #include<string.h>3 4 int main()5 {6 int i, j, max, n, m;7 char s[105][105];8 max0;9 memset(s, \0, sizeof(s)); 10 for (i0; gets(s[i]); i) 11 { 12 nstrlen(s[i]); 1…

node 大写_大写Node.js模块

node 大写Today, lets see a third party module that helps us in working with upper-case letters without necessarily typing them in upper-case in our source code. 今天&#xff0c;让我们看一个第三方模块&#xff0c;它可以帮助我们处理大写字母&#xff0c;而不必在…

1704:baoge的洗漱难题[黄]

baoge的洗漱难题[黄] Time Limit: 5000 ms Memory Limit: 65536 KB Total Submit: 79 Accepted: 21 Description众所周知&#xff0c;地大19楼的盥洗室非常小&#xff0c;所以经常会非常拥挤&#xff0c;很多时候去洗漱的时候不得不排很长的队。有时候baoge会排上半小时…

HDU嵌入式实验课程大作业分析报告

目录作业要求设计原理与思路扩展任务说明课程感受友情链接工程链接作业要求 体能测试记录仪设计 基于课程发放的实验板&#xff0c;设计一个带有计时和数据采集功能的体能测试记录仪。 基本设计内容 功能1&#xff1a;对应1000米体测场景&#xff0c;使用充电宝供电&#x…

COJ 1030 素数槽

http://acm.csu.edu.cn/OnlineJudge/problem.php?id1030 用线性筛素数果然快多了。 #include<cstdio> #include<cstring> #include<cstdlib> #define MAXN 1300000 bool is_p[MAXN];void calc() {for( int i 1; i < MAXN; i )is_p[i] true;is_p[1] fa…