How To Make Dropdown Menu That Is The Size Of Links Css
CSS Dropdowns
Create a hoverable dropdown with CSS.
Demo: Dropdown Examples
Move the mouse over the examples below:
Dropdown Text
Hello World!
Other:
Beautiful Cinque Terre
Basic Dropdown
Create a dropdown box that appears when the user moves the mouse over an chemical element.
Example
<manner>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
brandish: none;
position: absolute;
groundwork-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-alphabetize: 1;
}
.dropdown:hover .dropdown-content {
display: cake;
}
</mode>
<div class="dropdown">
<span>Mouse over me</span>
<div form="dropdown-content">
<p>Hello World!</p>
</div>
</div>
Try it Yourself »
Example Explained
HTML) Use any element to open up the dropdown content, e.g. a <span>, or a <button> element.
Use a container element (similar <div>) to create the dropdown content and add whatever y'all want inside of it.
Wrap a <div> element around the elements to position the dropdown content correctly with CSS.
CSS) The .dropdown
class uses position:relative
, which is needed when we want the dropdown content to be placed right below the dropdown button (using position:accented
).
The .dropdown-content
form holds the bodily dropdown content. It is hidden by default, and volition be displayed on hover (see below). Note the min-width
is set up to 160px. Feel free to change this. Tip: If y'all want the width of the dropdown content to be every bit wide every bit the dropdown button, set up the width
to 100% (and overflow:auto
to enable ringlet on pocket-size screens).
Instead of using a border, we have used the CSS box-shadow
holding to make the dropdown menu look like a "carte du jour".
The :hover
selector is used to show the dropdown menu when the user moves the mouse over the dropdown push button.
Dropdown Menu
Create a dropdown menu that allows the user to choose an choice from a list:
This example is like to the previous ane, except that nosotros add links inside the dropdown box and style them to fit a styled dropdown button:
Instance
<way>
/* Way The Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-cake;
}
/* Dropdown Content (Subconscious by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-ornamentation: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {groundwork-colour: #f1f1f1}
/* Show the dropdown carte on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Modify the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</way>
<div class="dropdown">
<button grade="dropbtn">Dropdown</push button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link two</a>
<a href="#">Link 3</a>
</div>
</div>
Endeavor it Yourself »
Right-aligned Dropdown Content
If you lot want the dropdown menu to get from correct to left, instead of left to right, add right: 0;
More Examples
Dropdown Prototype
How to add an prototype and other content within the dropdown box.
Hover over the image:
Beautiful Cinque Terre
Try it Yourself »
Dropdown Navbar
How to add together a dropdown carte du jour inside a navigation bar.
Try it Yourself »
How To Make Dropdown Menu That Is The Size Of Links Css,
Source: https://www.w3schools.com/css/css_dropdowns.asp
Posted by: bynumslearearal.blogspot.com
0 Response to "How To Make Dropdown Menu That Is The Size Of Links Css"
Post a Comment