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.pswp.cn/news/377517.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377517.shtml
英文地址,請注明出處:http://en.pswp.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…