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>
Related
<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;}
I am trying to resize dropdown menu, where I have text+picture. But the border is making part of the menu bigger, and that's the issue. I need to have text and under the text the picture of product. Is there any way to do it by css?
HTML
<div class="wrap">
<div class="header">
<img src="./images.png" class="image" alt="logo" />
<div class="dropdown">
<button class="dropbtn">Menu</button>
<div class="dropdown-content">
Roofs<img src="https://insta-galery.w3spaces.com/strecha.jpg"/>
Link 2
Link 3
</div>
</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>
</div>
</body>
CSS
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
margin-top: 1px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.image{
display: flex;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 1px 1px;
text-decoration: none;
display: block;
border-radius: 10px;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: flex;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
I changed this:
.dropdown:hover .dropdown-content {display: flex;}
display: flex to block. It solved my problem.
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;}
I currently have a navigation bar with typical links "Home, About, Resume, Contact".
I currently have code so when you hover over Resume (by default has an arrow pointing down), a dropdown appears and the direction of the arrow changes to point up using two span classes (code is below).
What I want to achieve is while hovering over the dropdown contents, the arrow is still pointing up (currently it reverts to pointing down while hovering over dropdown links).
Here is the current Code:
CSS/HTML:
/* Navbar links besides Resume */
.container1 {
overflow: hidden;
font-family: Cabin,Helvetica,Arial,sans-serif; /*changes font of name, about, contact*/
text-align: center;
}
/*Navbar links besides Resume */
.container1 a {
display: inline;
font-size: 30px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline;
vertical-align: middle;
}
/* Affects Resume*/
.dropdown .dropbtn {
display: inline;
font-size: 30px;
font-family: Cabin,Helvetica,Arial,sans-serif;
border: none;
outline: none;
color: inherit;
padding: 14px 16px;
background-color: inherit;
}
/* color of Resume when hovered */
.container a:hover, .dropdown:hover .dropbtn {
background-color: inherit;
}
button .hover { display: none; }
button:hover .no_hover { display: none; }
button:hover .hover { display: inline; }
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
left: 52.3%;
background-color: white;
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 {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* 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;
}
<div class="container1">
<a id="home" href="#">Michael Geng</a>
<a id="about" href="#">About</a>
<div class="dropdown">
<a id = "resume" href="#"><button class="dropbtn">
<span class="no_hover">Resume ▼</span>
<span class="hover">Resume ▲</span>
</button></a>
<div class="dropdown-content">
<a id = "objective" href="#">Objective</a>
<a id = "education" href="#">Education</a>
<a id = "skills" href="#">Skills</a>
</div> <!-- dropdown-content -->
</div> <!-- dropdown -->
<a id="contact" href="#">Contact</a>
</ul>
</div> <!--container1 -->
My current thought this line of code where when you hover over the dropdown contents to change the display but I have not got it working:
.dropdown-content:hover ~ .no_hover{display: none; }
.dropdown-content:hover ~ .hover{display: inline; }
You need to change the CSS that triggers the appropriate arrow span to be displayed to be based on hovering over .dropdown. See updated snippet.
/* Navbar links besides Resume */
.container1 {
overflow: hidden;
font-family: Cabin,Helvetica,Arial,sans-serif; /*changes font of name, about, contact*/
text-align: center;
}
/*Navbar links besides Resume */
.container1 a {
display: inline;
font-size: 30px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline;
vertical-align: middle;
}
/* Affects Resume*/
.dropdown .dropbtn {
display: inline;
font-size: 30px;
font-family: Cabin,Helvetica,Arial,sans-serif;
border: none;
outline: none;
color: inherit;
padding: 14px 16px;
background-color: inherit;
}
/* color of Resume when hovered */
.container a:hover, .dropdown:hover .dropbtn {
background-color: inherit;
}
button .hover { display: none; }
.dropdown:hover .no_hover { display: none; }
.dropdown:hover .hover { display: inline; }
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
left: 52.3%;
background-color: white;
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 {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* 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;
}
<div class="container1">
<a id="home" href="#">Michael Geng</a>
<a id="about" href="#">About</a>
<div class="dropdown">
<a id = "resume" href="#"><button class="dropbtn">
<span class="no_hover">Resume ▼</span>
<span class="hover">Resume ▲</span>
</button></a>
<div class="dropdown-content">
<a id = "objective" href="#">Objective</a>
<a id = "education" href="#">Education</a>
<a id = "skills" href="#">Skills</a>
</div> <!-- dropdown-content -->
</div> <!-- dropdown -->
<a id="contact" href="#">Contact</a>
</ul>
</div> <!--container1 -->
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>