Large menu help adding in another link button - html

I was looking at the mega menus on the w3schools website: (https://www.w3schools.com/howto/howto_css_mega_menu.asp).
Using the "try it yourself", I was playing around with it, but struggling to see how to add another mega menu or another link button next to the dropdown link.
Can anyone help me out?

Please check the code below, might help you:
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial, Helvetica, sans-serif;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content .header {
background: red;
padding: 16px;
color: white;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
background-color: #ccc;
height: 250px;
}
.column a {
float: none;
color: black;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
}
.column a:hover {
background-color: #ddd;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.column {
width: 100%;
height: auto;
}
}
<div class="navbar">
Home
News
<!-- START FIRST DROPDOWN -->
<div class="dropdown">
<button class="dropbtn">First Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="header">
<h2>Mega Menu - first dropdown</h2>
</div>
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
<!-- END FIRST DROPDOWN -->
<!-- START SECOND DROPDOWN -->
<div class="dropdown">
<button class="dropbtn">Second Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="header">
<h2>Mega Menu - second dropdown</h2>
</div>
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
<!-- END SECOND DROPDOWN -->
</div>

The code which gives you the megamenu is the following:
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="header">
<h2>Mega Menu</h2>
</div>
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
Hope this is what you were looking for.
Please try to add some code to your question next time. It will be easier and quicker to analyze.
Regards

Related

CSS heml, JS mega menu

Please help.
When mouseover on "Products" tab the "services" items shifts to the right. I need help on the CSS settings.
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial, Helvetica, sans-serif;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
position: relative;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content .header {
background: red;
padding: 4px;
color: white;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
background-color: #ccc;
height: 250px;
}
.column a {
float: none;
color: black;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
}
.column a:hover {
background-color: #ddd;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
<table width=960 border=0 cellspacing=0 cellpadding=0 align=center bgcolor='#bbeeff' style='padding:10px'>
<tr>
<td>
<div class="navbar">
<div class="dropdown">
<button class="dropbtn">Products
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<!-- <div class="header">
<h2>...</h2>
</div> -->
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Services
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<!-- <div class="header">
<h2>...</h2>
</div> -->
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
<div style="padding:16px">
<p>home page ....</p>
</div>
</td>
</tr>
</table>
.dropdown-content {
position: absolute;
position: relative;
}
These two are mutually exclusive. What you actually want is to put position: relative on the parent element, .dropdown.
You will also have to remove overflow: hidden on the parent .dropdown and .navbar or the dropdown, which is outside of the element's frame, will not show.
Finally, because you've floated everything and nothing has a defined width, you will have to set a non-% width/height on some elements. I added height: 46px to your navbar and width: 500px to your .row.
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.navbar {
height: 46px;
background-color: #333;
font-family: Arial, Helvetica, sans-serif;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
position: relative;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content .header {
background: red;
padding: 4px;
color: white;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Create three equal columns that floats next to each other */
.row
{
width: 500px;
}
.column {
float: left;
width: 33.33%;
padding: 10px;
background-color: #ccc;
height: 250px;
}
.column a {
float: none;
color: black;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
}
.column a:hover {
background-color: #ddd;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
<table width=960 border=0 cellspacing=0 cellpadding=0 align=center bgcolor='#bbeeff' style='padding:10px'>
<tr>
<td>
<div class="navbar">
<div class="dropdown">
<button class="dropbtn">Products
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<!-- <div class="header">
<h2>...</h2>
</div> -->
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Services
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<!-- <div class="header">
<h2>...</h2>
</div> -->
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
<div style="padding:16px">
<p>home page ....</p>
</div>
</td>
</tr>
</table>

I am having trouble with getting my navigation to take up my flexbox. The navigation only takes up a small portion of the box it's in

The code when ran doesn't fill the flexbox like I would like it to do, and I want to continue to be more so responsive to size changes. I have pulled resources from a lot of places and still can't find out why it isn't working. I came here because I often use this site to help with other work as well.
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Header */
.column, .columna, .columnab, .columnb {
align-items: center;
text-align: center;
border: solid;
border-width: thin;
max-height: 20em;
}
.column {
flex: 33%;
}
.columna {
width: 100%;
}
.columnab {
width: 22%;
}
.columnb {
width: 17%;
}
.row {
min-height: 10em;
display: flex;
flex-wrap: wrap;
background-color: #FF9176;
}
/* Navigation Section */
.dropbtn {
background-color: #FF9176;
color: #0061A0;
font-size: 75%;
font-family: 'Solway', serif;
padding: 16px;
border: none;
cursor: pointer;
}
.dropbtn:hover, .dropbtn:focus {
background-color: #FEB384;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
width: 100%;
position: absolute;
background-color: #FEB384;
min-width: 160px;
overflow: auto;
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 a:hover {background-color: #FECE9D;}
.show {display: block;}
<header>
<div class="row">
<div class="column" style="padding: 0">
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 1</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 2</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 3</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 4</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
</div>
<div class="column">
<h6> LOGO </h6>
<img src="images/print_studio_logo.***" alt="Print Studio's Logo">
</div>
<div class="column" style="padding: 0">
<div class="columna" style="height: 50%;">
<h6> INSERT CART / LOGIN </h6>
</div>
<div class="columna" style="height: 50%;">
<h6> INSERT SOCIAL </h6>
</div>
</div>
</div>
</header>
Welcome to stack overflow. Your question is not very clear could you be more precised about the element you would like to fill, by pointing classes or maing img.
For now I adjusted the width of your dropdown class that were not by 100%
.dropdown{
width: 100%;
}
.dropdown button {
width: 100%;
}
DEMO based on what I understood.
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Header */
.column, .columna, .columnab, .columnb {
align-items: center;
text-align: center;
border: solid;
border-width: thin;
max-height: 20em;
}
.column {
flex: 33%;
}
.columna {
width: 100%;
}
.columnab {
width: 22%;
}
.columnb {
width: 17%;
}
.row {
min-height: 10em;
display: flex;
flex-wrap: wrap;
background-color: #FF9176;
}
/* Navigation Section */
.dropbtn {
background-color: #FF9176;
color: #0061A0;
font-size: 75%;
font-family: 'Solway', serif;
padding: 16px;
border: none;
cursor: pointer;
}
.dropbtn:hover, .dropbtn:focus {
background-color: #FEB384;
}
.dropdown {
position: relative;
display: inline-block;
width:100%;
}
.dropdown-content {
display: none;
width: 100%;
position: absolute;
background-color: #FEB384;
min-width: 160px;
overflow: auto;
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 a:hover {background-color: #FECE9D;}
.dropdown button{ width:100%;}
.show {display: block;}
<header>
<div class="row">
<div class="column" style="padding: 0">
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 1</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 2</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 3</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
<div class="columna">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">GROUP 4</button>
<div id="myDropdown" class="dropdown-content">
Item 1
Item 2
Item 3
</div>
</div>
</div>
</div>
<div class="column">
<h6> LOGO </h6>
<img src="images/print_studio_logo.***" alt="Print Studio's Logo">
</div>
<div class="column" style="padding: 0">
<div class="columna" style="height: 50%;">
<h6> INSERT CART / LOGIN </h6>
</div>
<div class="columna" style="height: 50%;">
<h6> INSERT SOCIAL </h6>
</div>
</div>
</div>
</header>

Dropdown menu open under div

I need help with this site: http://www.jsdkqwoj.eu/
In mobile drop down menu goes under the div. Tried z-index:9999 for the header / topnav elements and z-index:-9999 to div. Not help. Also tried this Dropdown menu hidden under div and it is not helping.
I googled yesterday few hours and tried many things, and not helping. I also would like to get image top of the page under the header, but i am satisfied of the menu fix.
I linked the page but here is code of the top nav/header and div.
Summary: I want menu open over the div and image shows behind the menu dropdown. I can do dropdown menu like pushing down the div, but that is not what i want.
CSS
header {
background-color: rgba(0,0,0,0.7);
width: 100%;
height: 100px;
}
.topnav {
overflow: hidden;
background-color: rgba(0,0,0,0.7);
position: relative;
}
.topnav #myLinks {
display: none;
}
.topnav a {
color: white;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
display: block;
height: 60px;
}
.topnav2 a {
text-align: center;
}
.topnav a.icon {
display: block;
position: absolute;
right: 0;
top: 0;
height: 90px;
width: 90px;
}
.topnav2 a:hover {
background-color: rgba(0,0,0,0.4);
color: #ff6000;
}
TOPNAV
<h2 class="black">OSKARI ALAJÄRVI</h2><p class="light">Portfolio</p>
<div class="topnav2" id="myLinks">
Home
Blog
Contact
</div>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="hamburger_bars" onclick="myFunction2(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</i>
</a>
</div>
DIV
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-sm pt-5 pb-5">
<div class="etusivun_teksti" data-aos="fade-up">
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<?php the_content();?>
<?php endwhile; endif;?>
</div>
</div>
<div class="col-sm etusivun_kuva"></div>
</div>
</div>
</div>
.topnav2{
position:relative;
z-index:1;
}
Add this to your css. Hope this works

bootstrap 4 dropdown menu over div below

Im trying to get the bootstrap 4 responsive top nav to appear over my container div with no luck, and I cant seem to find a solution for it.
Here is how the Top nav is supposes to work
W3Schools editor
and here is my jsfiddle of the code
jsfiddle
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: #4CAF50;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: visible;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: relative;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 2;
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
#media screen and (max-width: 600px) {
.topnav a:not(:first-child),
.dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .dropdown-content {
position: relative;
}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
<button class="dropbtn">Equipment
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Manage equipment
Add equipment
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Stock
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Manage stock
Add stock
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Reports
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Report 1
Report 1
Report 1
</div>
</div>
☰
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<?php echo display_msg($msg); ?>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="panel panel-box clearfix">
<div class="panel-icon bg-green">
<i class="glyphicon glyphicon-user"></i>
</div>
<div class="panel-value pull-right">
<h2 class="margin-top">
<?php echo $c_contractors['total']; ?> </h2>
<p class="text-muted">Contractors</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-box clearfix">
<div class="panel-icon pull-left bg-red">
<i class="glyphicon glyphicon-list"></i>
</div>
<div class="panel-value pull-right">
<h2 class="margin-top">
<?php echo $c_jobs_active['total']; ?> </h2>
<p class="text-muted">Active Jobs</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-box clearfix">
<div class="panel-icon pull-left bg-blue">
<i class="glyphicon glyphicon-list"></i>
</div>
<div class="panel-value pull-right">
<h2 class="margin-top">
<?php echo $c_jobs_pending['total']; ?> </h2>
<p class="text-muted">Pending jobs</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-box clearfix">
<div class="panel-icon pull-left bg-yellow">
<i class="glyphicon glyphicon-list"></i>
</div>
<div class="panel-value pull-right">
<h2 class="margin-top">
<?php echo $c_jobs_completed['total']; ?>
</h2>
<p class="text-muted">Completed Jobs YTD</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="jumbotron text-center">
<h1>Any problems let me know.</h1>
</div>
</div>
</div>
</div>
</div>
I am sure it is something simple that I have over looked
Cheers,
Firstly, change the .topnav class to:
.topnav {
float:left;
width:100%;
position:relative;
background-color: #333;
}
Then remove the overflow from .dropdown class. Finally, change position: relative to position: absolute in the .dropdown-content class.
Don't forget to add a clear: both style before the container-fluid.
Here's the Fiddle.

vertical navbar buttons displaced by nav content

I've been trying to solve this for 2 days now and tried everything I can think of. Ive tried a thousand combos of position, display, and floats.
I am trying to make a vertical navigation bar in which the content of the navigation buttons comes out as a 2nd tier of vertical buttons and from the second set comes a 3rd tier of vertical buttons, etc.
My problem is that the 2nd tier of buttons displaces the buttons in 1st tier. Strangely the 3rd tier does not displace the 2nd or 1st tier.
I have attached a JSfiddle.
<html>
<head>
<style>
.dropdown {
position: relative;
display: block;
clear: both;
margin: 5px;
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
float: left;
min-width: 100px;
margin-top: 5px;
}
.dropdown-options {
display: none;
min-width: 160px;
z-index: 1;
}
.dropbtncontent {
min-width: 160px;
border: none;
font-size: 16px;
background-color: #4CAF50;
color: white;
padding: 2px;
text-decoration: none;
margin: 2px;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 1;
}
.dropdown:hover .dropdown-options {
display: block;
}
.dropdown-options:hover .dropdown-content {
display: inline-block;
}
.dropdown-content a {
background-color: #4CAF50;
color: white;
padding: 2px;
text-decoration: none;
margin: 2px;
display: block;
}
</style>
</head>
<body>
<div class="dropdown">
<button class="dropbtn">Dropdown1</button>
<div class="dropdown-options">
<button class="dropbtncontent">Dropdown1.1</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<div class="dropdown-options">
<button class="dropbtncontent">Dropdown1.2</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<div class="dropdown-options">
<button class="dropbtncontent">Dropdown1.3</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Dropdown2</button>
<div class="dropdown-content">
Link 3
Link 2
Link 4
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Dropdown3</button>
<div class="dropdown-content">
Link y
Link r
Link a4
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Dropdown4</button>
<div class="dropdown-content">
Lin
Lin 2
Lk 4
</div>
</div>
</body>
</html>
If anyone has any suggestions, I'd really appreciate it.
You can achieve the desired effect by changing your .dropbox class to this:
.dropdown {
position: relative;
display: block;
clear: both;
margin: 5px;
//new code below
overflow:show;
height: 50px;
}
The fixed height would cause some of the 2nd tier options to show until it reached the height.
With that, by setting overflow:show you allow children to show even if they're bigger than it's parent size without affecting other elements.