<div class="navbar">
home
news
about
<div class="dropdown">
<button class="dropbtn">gallery </button>
</div>
</div>
I want to create a submenu in this code, can you help me?
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
For CSS try this:
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
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-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #3e8e41;}
Related
[i am new to website design, any help is appreciated]
This code is for having the dropdown button links appear in a list form, what i am trying to do is when you hover over the "More about Us", the links will show on the right side of the button
[HTML]
<div class ="Links">
<div class="dropdown">
<button class="dropbtn">More About Us</button>
<div class="dropdown-content">
Employees
What we do
FAQ
</div>
</body>
</html>
[CSS]
/* Dropdown Button */
.dropbtn {
background-color: brown;
color: white;
padding: 10px;
font-size: 40px;
border: outset;
font-family: Agency FB;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
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-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #B9DADC;}
OK, if now i understand what do you want you can solve this adding the position at the .dropdown-content.
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
left: 100%;
top:0;
}
/* Dropdown Button */
.dropbtn {
background-color: brown;
color: white;
padding: 10px;
font-size: 40px;
border: outset;
font-family: Agency FB;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
/*SET POSITION TO THE RIGHT AND TOP OF PARENT BOUNDARIES*/
left: 100%;
top:0;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #B9DADC;}
<html>
<body>
<div class ="Links">
<div class="dropdown">
<button class="dropbtn">More About Us</button>
<div class="dropdown-content">
Employees
What we do
FAQ
</div>
</body>
</html>
I loose the fact that you want the link displayed all inline. To achieve this you have to set a fixed dimensione of .dropdown-content like :
width: 350px;
and the display of a element, like
display: inline-block;
/* Dropdown Button */
.dropbtn {
background-color: brown;
color: white;
padding: 10px;
font-size: 40px;
border: outset;
font-family: Agency FB;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
/*SET POSITION TO THE RIGHT AND TOP OF PARENT BOUNDARIES*/
left: 100%;
top:0;
width:350px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
display:inline-block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #B9DADC;}
<html>
<body>
<div class ="Links">
<div class="dropdown">
<button class="dropbtn">More About Us</button>
<div class="dropdown-content">
Employees
What we do
FAQ
</div>
</body>
</html>
This is not sure the best solution but at the moment it is the only solution that comes to my mind.
Maybe you can try playing with
display: flex;
adding it to the .dropdown-content and then working on child element
I want to implement a navigation menu that displays another detail menu on hover.
just like the one used in ktm website.
/* 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-block;
}
/* Dropdown Content (Hidden 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);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<div class="dropdown">
<a class="dropbtn">Dropdown</a>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
you can edit the css file to add your custom style when dropping down
I have a dropdown box presented on W3CSchools that I wish to convert into less class-oriented CSS (rather than having a bunch of classes, I'll just select it through the primary parent).
Here's the HTML:
<nav>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</nav>
(Effectively, I shouldn't have to have any classes here)
Here's the CSS:
/* Style 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-block;
}
/* Dropdown Content (Hidden 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);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
Everything here works fine when converted over to being targetted merely by the nav element, apart from the functional stuff:
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
I can try to convert these into,
nav > div:hover nav > div > div {
display: block;
}
nav > div:hover mav > div > button {
background-color: #3e8e41;
}
But nothing happens. I've even tried using the primary parent class of .dropdown and removing the beginning of nav > div, although it also returns nothing.
What is making the difference? I'm targeting exactly the same elements.
You have a typo in nav > div:hover mav > div > button { mav should be nav so maybe that caused you problems with testing.
Here is the relevant code without using classes:
/*selects the nav and then select the div that is the immediate child of the nav that is hovered. When that child div is hovered it selects the first div and sets its display type to block*/
nav > div:hover > div:first-of-type{
display: block;
}
nav > div:hover > button{
background-color: #3e8e41;
}
/* Style 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-block;
}
/* Dropdown Content (Hidden 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);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1;}
nav > div:hover > div:first-of-type{
display: block;
}
nav > div:hover > button{
background-color: #3e8e41;
}
<nav>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</nav>
Hi there I have this button that has been driving me crazy!
Here is the jfiddle
HTML:
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
CSS:
/* Dropdown Button */
.dropbtn {
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
outline:none;
text-shadow:none !important;
box-shadow:none !important;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden 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);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover {
background-color: #3e8e41;
}
.dropbtn:hover
{
text-color: black;
}
As you can see when the button is clicked or currently showing the child links it is green! I'm trying to make it transparent so only the text shows.
I thought it was a :hover or :active but that never seemed to work so I have no idea what is causing it to turn green or how I can fix this. Any help?
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover {
background-color: #3e8e41;
}
Should be
.dropdown:hover {
background-color: transparent;
}
To make it solid - use a couple pseudo-classes
.dropdown:hover,
.dropdown:focus,
.dropdown:active {
background-color: transparent;
}
I am trying to create pure and simple HTML+CSS drop down menu which will open in a full width mode underneath each item and will also push content. This image and jsfiddle better explains what I am trying to achieve:
jsfiddle.net/66qez5tn
How do I do this ?
This code can do the drop down menu with HTML and CSS:
<style>
/* Style 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-block;
}
/* Dropdown Content (Hidden 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);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>