I am not able to create CSS Dropdown menu - html

I was just trying to make a dropdown menu. But it is not working. What is the error?
.dropdown1{
width: 200px;
height: 110px;
background-color: white;
border: 5px solid black;
position:absolute;
left: 400px;
opacity: 0;
}
.about_us1:hover .dropdown1{
opacity: 1;
}
<div class="header">
<strong> <h3 style="position: relative;top: 2px;left: 200px;font-weight: 1000;font-size: 30px;">HOME</h3></strong>
<strong> <h3 class="about_us1" style="position: relative;top: -30px;left: 400px;font-weight: 1000;font-size: 30px;">ABOUT US</h3></strong>
<center>
<div class="dropdown1">
<h3>Our Motto</h3>
<br>
<h3>Admission</h3>
<br>
<h3>Principal's Desk</h3>
</div>
</center>
<strong> <h3 style="position: relative;top: -65px;left: 700px;font-weight: 1000;font-size: 30px;">ACADEMIC</h3></strong>
<strong> <h3 style="position: relative;top: -100px;left: 1000px;font-weight: 1000;font-size: 30px;">INFRASTRUCTURE</h3></strong>
<strong> <h3 style="position: relative;top: -135px;left: 1450px;font-weight: 1000;font-size: 30px;">ADMISSION</h3></strong>
</div>
Or instead of opacity I have tried two things.. (visibility:hidden and visibility: visible) or (display: none and display: block). Its still not working with these three trials

Usually you would want your dropdown list to be contained with the button it belongs to. So where you have a dropdown containing Academic, Infrastructure and Admission this would all want to be contained with the About Us button. Here is some code from w3schools...
HTML
<div class="dropdown">
<button class="dropbtn">Button1</button>
<div class="dropdown-content">
Link1
Link2
Link3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Button2</button>
<div class="dropdown-content">
Link4
Link5
Link6
</div>
</div>
CSS
/* Dropdown Button */
.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

How to turn one of the menu options into a dropdown menu

<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;}

How to fixed block size of a dropdown-Menu

I have a dropdown menu of libraries. Each library may have sub-objects into them (they are in the attribute . Internal Elements) or not. When i hover over a library with instances it shows another menu to the right. The problem is that the first menu is changing sizes when this happens making it ugly and when i hover over the last library (without instances) it changes size at the same time and blocks the menu al together.
How it looks
The HTML:
<div class="row">
<div class="col-md-11">
<a href="#"
class="list-group-item clearfix"
(click)="onSelected()">
<div class="pull-left">
<h4 class="list-group-item-heading">{{picture.Name}}</h4>
</div>
</a>
<div *ngIf="dropdownflag">
<app-xml-element *ngFor="let component of components" [component]="component"></app-xml-element>
</div>
</div>
<div class="col-md-1.5">
<div class="dropdown">
<button class="dropbtn"><span class="glyphicon glyphicon-plus"></span></button>
<div class="dropdown-content">
<div *ngFor="let librarie of libraries">
<div *ngIf="librarie.InternalElements.length>=1; else empty">
<div class="right">
<a class="dropright" >{{librarie.Name}}</a>
<div class="right-content">
<div *ngFor="let instance of librarie.InternalElements">
<a (click)="addElement(librarie,instance)">{{instance.Name}}</a>
</div>
</div>
</div>
</div>
<ng-template #empty>{{librarie.Name}}</ng-template>
</div>
</div>
</div>
<button role="button" (click)="dropdown()" *ngIf="picture.InternalElements.length>=1"><span class="caret"></span></button>
</div>
</div>
CSS:
/* Dropdown Button */
.dropbtn {
background-color: black;
color: white;
padding:5px;
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;}
/*Right menu container*/
.right {
position: relative;
display: inline-block;
}
/* content on 2nd menu*/
.right-content {
display: none;
position: relative;
left:160px;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/*ensure that a has the same format as previous class a*/
.right-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/*hoverable a tag to show 2nd menu*/
.dropright {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Show the 2nd menu on hover right */
.right:hover .right-content {
display: block;
}
hello buddy the reason behind your dropdown not working properly is because you are using relative in your child div here is the code hopefully its good for you
/* Dropdown Button */
.dropbtn {
background-color: black;
color: white;
padding:5px;
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;
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;}
/*Right menu container*/
.right {
position: relative;
display: inline-block;
}
/* content on 2nd menu*/
.right-content {
display: none;
position: absolute;
left: 152px;
background-color: #f1f1f1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
top: 0;}
/*ensure that a has the same format as previous class a*/
.right-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/*hoverable a tag to show 2nd menu*/
.dropright {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Show the 2nd menu on hover right */
.right:hover .right-content,.right:focus .right-content{
display: block;
}
<div class="container">
<div class="row">
<div class="col-md-11">
<a href="#" class="list-group-item clearfix" (click)="onSelected()">
<div class="pull-left">
<h4 class="list-group-item-heading">{{picture.Name}}</h4>
</div>
</a>
<div *ngIf="dropdownflag">
<app-xml-element *ngFor="let component of components" [component]="component"></app-xml-element>
</div>
</div>
<div class="col-md-1.5">
<div class="dropdown">
<button class="dropbtn"><span class="glyphicon glyphicon-plus"></span></button>
<div class="dropdown-content">
<div *ngFor="let librarie of libraries">
<div *ngIf="librarie.InternalElements.length>=1; else empty">
<div class="right">
<a class="dropright">{{librarie.Name}}</a>
<div class="right-content">
<div *ngFor="let instance of librarie.InternalElements">
<a (click)="addElement(librarie,instance)">{{instance.Name}}</a>
</div>
</div>
</div>
</div>
<ng-template #empty>{{librarie.Name}}</ng-template>
</div>
</div>
</div>
<button role="button" (click)="dropdown()" *ngIf="picture.InternalElements.length>=1"><span
class="caret"></span></button>
</div>
</div>
</div>

Center and contain menu div

I'm building a hover menu using css and bootstrap(for flex grid). If I try to put my menu in any parent div, my menu only goes as wide as the parent div.
Also I can't seem to center my hover menu to the length of my menu item.
So, how can I make my menu items stretch the width so the text does not wrap onto a new line and how do I center the whole menu relevant to it's link?
html
<div class="d-flex flex-row">
<div class="dropdown">
<button class="dropbtn">Small</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Long Menu item</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">a really long Long Menu item</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
</div>
CSS
/* Dropdown Button */
.dropbtn {
color: #3a3a3a;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background: #fff;
border: 1px solid #cecece;
color:#3a3a3a;
z-index: 1;
box-sizing: border-box;
}
.dropdown-content:after, .dropdown-content:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.dropdown-content:after {
border-bottom-color: #fff;
border-width: 13px;
margin-left: -13px;
}
.dropdown-content:before {
border-bottom-color: #cecece;
border-width: 14px;
margin-left: -14px;
}
/* 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 {
color:$green;
}
/* 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;
}
how can I make my menu items stretch the width so the text does not wrap onto a new line?
You can use the css property white-space: nowrap;, so Text will never wrap to the next line. See docs: https://www.w3schools.com/cssref/pr_text_white-space.asp
new line and how do I center the whole menu relevant to it's link?
So you can set a position left:50% and then use the transform property setting the value translateX(50%) to bring it back 50% of its size. Add the following to .dropdown-content :
left: 50%;
transform: translateX(-50%);
/* Dropdown Button */
.dropbtn {
color: #3a3a3a;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background: #fff;
border: 1px solid #cecece;
color:#3a3a3a;
z-index: 1;
box-sizing: border-box;
left: 50%;
transform: translateX(-50%);
}
.dropdown-content:after, .dropdown-content:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.dropdown-content:after {
border-bottom-color: #fff;
border-width: 13px;
margin-left: -13px;
}
.dropdown-content:before {
border-bottom-color: #cecece;
border-width: 14px;
margin-left: -14px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
white-space: nowrap;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
color:$green;
}
/* 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;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="d-flex flex-row">
<div class="dropdown">
<button class="dropbtn">Small</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Long Menu item</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">a really long Long Menu item</button>
<div class="dropdown-content">
Link 1 long link
Link 2
Link 3
</div>
</div>
</div>

Trouble with dropdown menu

Hi I'm trying to make a dropdown menu on the pictures but when I try to get to the links I can't the menu closes, i want the menu under the picture boxes where it is but fixed, please help, Thanks :)
Also im using Wordpress and visual composer
Site: http://www.corebusinesssa.co.za/Test/
HTML:
<div class="dropdown">
<h6 style="text-align: center;"><span style="color: #000000;"><strong>4K/HD Camcorders</strong></span><img class="dropdownimg dropdownimg2 aligncenter wp-image-391 size-full" src="http://www.corebusinesssa.co.za/Test/wp-content/uploads/2016/09/4k-cameras.png" width="104" height="70" /></h6>
<div class="dropdown-content">
Varicam
AG-DVX 200
AG-GH4U
UX Series
GH4
AG-AC30
Consumer HD
</div>
</div>
CSS:
/* The container - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
width: 106%;
height:95px;
top: -25px;
left: -6px;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
overflow:auto
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
top: 125px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 0px 16px;
text-decoration: none;
text-align:center;
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;
}
Move the div inside the h6 and then adjust the position to top:100%.
/* The container - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
width: 106%;
height: 95px;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
top: 100%;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
h6:hover .dropdown-content {
display: block;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 0px 16px;
text-decoration: none;
text-align: center;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #f1f1f1
}
<div class="dropdown">
<h6 style="text-align: center;"><span style="color: #000000;"><strong>4K/HD Camcorders</strong></span><img class="dropdownimg dropdownimg2 aligncenter wp-image-391 size-full" src="http://www.corebusinesssa.co.za/Test/wp-content/uploads/2016/09/4k-cameras.png" width="104" height="70" />
<div class="dropdown-content">
Varicam
AG-DVX 200
AG-GH4U
UX Series
GH4
AG-AC30
Consumer HD
</div>
</h6>
</div>

Dropdown Menu covered by div

Hello I want to add a dropdown menu to my top navigation bar.
But for some reason it gets hidden by my image slider.
I would like the dropdown content to be on top of everything as it should be.
/* Style The Dropdown Button */
.dropbtn {
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
z-index: 999;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: white;
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;
}
<div id="header">
<ul>
<li>
<a class="a-no-hover" href="index.html">
<img src="images/miniLogo.png" />
</a>
</li>
<li><a class="active" href="index.html">HOME</a>
</li>
<div class="dropdown">
<li class="dropbtn">PRODUCTS
</li>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<li>ORDER
</li>
<li>ABOUT US
</li>
<li>CONTACT US
</li>
</ul>
</div>
<div id="section1">
<img id="img" src="images/bg.jpg" />
</div>
You are giving z-index to the header menu, that's fine. But the content is what is the problem. So, try giving z-index to the .dropdown-content:
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1000; /* One more than the header. */
}
Update
#header ul {
list-style-type: none;
margin: 0;
padding: 0;
/* overflow: hidden; Remove this. */
text-align: center;
vertical-align: middle;
}
Preview
Output: http://jsbin.com/lorebubizi/1