make submenu wider than main menu - html

I have this submenu and I would like it so that when the dropdown menu is out it has a width of 100% and covers the whole page. At the moment if I change the width to 100% it just makes it the same width as the main menu.
This is my current HTML:
<header>
<div class="header">
<div class="nav">
<ul>
<li> Services
<ul class="sub"> <a href="services.html#branddesign">
<li><img class="imgcenter" src="images/Brand-Design-Circle-Blue.png" width="100px" />
<br>
Brand Design
</li></a>
<a href="services.html#brandonline">
<li><img class="imgcenter" src="images/Brand-Online-Circle-Blue.png" width="100px" />
<br>
Brand Online
</li></a>
<a href="services.html#brandmarketing">
<li><img class="imgcenter" src="images/Brand-Marketing-Circle-Blue.png" width="100px" />
<br>
Brand Marketing
</li></a>
<a href="services.html#brandmanagement">
<li><img class="imgcenter" src="images/Brand-Management-Circle-Blue.png" width="100px" />
<br>
Brand Management
</li></a>
</ul>
</li>
<li> Clients
</li>
<li> About
</li>
<li> Contact Us
</li>
</ul>
</div>
</div>
</div>
and this CSS:
.header {
position: fixed;
display: block;
float: left;
width: 100%;
height: auto;
background-color: #666;
z-index: 9999;
}
.nav {
position: static;
float: left;
width: 500px;
height: 50px;
margin: 10px 5px;
}
.nav a {
text-decoration: none;
color: #FFFFFF;
}
.nav ul > li:first-child {
padding-bottom: 25px;
}
.nav a:hover {
text-decoration: none;
color: #6db6e5;
}
.nav li {
font-family: "eras_demi_itcregular", Arial, Helvetica;
list-style: none;
float: left;
margin-right: 50px;
}
.nav li:hover a:hover {
padding-bottom: 5px;
border-bottom: 2px solid #6db6e5;
color: #6db6e5;
}
.nav ul li:hover > ul {
height:150px;
}
.nav ul {
list-style: none;
position: absolute;
display: inline-block;
margin-top: 23px;
}
.nav ul ul {
width: 494px;
background: #7d7c7c;
height: 0px;
overflow: hidden;
padding-left:0;
margin-left:0;
font-size: 12px;
text-align: center;
-webkit-transition:all .5s ease-in-out;
-moz-transition:all .5s ease-in-out;
-o-transition:all .5s ease-in-out;
transition:all .5s ease-in-out;
}
.nav ul ul li {
padding: 10px;
margin-left: -1px;
margin-right: 0;
height: 129px;
}
.nav ul ul li:last-child {
}
.nav ul ul li:hover {
background: #666;
}
.nav li li {
height:130px;
-webkit-transition:all .3s ease-in-out;
}
Can anyone please tell me how I can make it so that the submenu can be wider than the main menu?

Try adding this to your CSS:
nav ul ul {
width: 100vw;
left: 0;
}
Fiddle: http://jsfiddle.net/9QE58/1/embedded/result/
That should keep it at 100% of the viewport width no matter what the pixel width is.

Related

Dropdown menu not staying when I take the mouse over it

As the title suggests, I've made this dropdown menu and i don't know for what reason when i take my mouse over it or i remove the mouse from the parents element which has the hover effect the dropdown dissapears, i want it to stay so that the user can select.
.sub-menu{
display: none;
}
.sub-menu ul li{
margin: 15px;
width: 120px;
padding: 15px;
}
.navbar-header ul li:hover .sub-menu{
display: block !important;
position:absolute;
background: white;
margin-top: 15px;
margin-left: -15px;
}
.sub-menu ul:hover {
display: block !important;
}
.navbar-header ul li:hover .sub-menu ul{
display: block;
margin: 10px;
-o-transition:.3s ease;
-ms-transition:.3s ease;
-moz-transition:.3s ease;
-webkit-transition:.3s ease;
transition:.3s ease;
outline: none;
}
.sub-menu ul li:hover {
display: block;
background: #f69220;
}
.sub-menu ul li a{
color: black;
}
.navbar-header ul li:hover .sub-menu ul li{
display: block !important;
color: black ;
width: 150px;
padding: 5px;
border-radius: 0;
text-align: center;
}
<div class="navbar-header" style="padding: 0; margin: 0; ">
<ul class="navbar-ul">
<li> <a routerLink="/home"><img src="" class="navbar-logo" alt=""></a>
</li>
<!-- logo -->
<!-- <li><a routerLink="/home">Home</a></li> -->
<!-- <li><a routerLink="/aboutus">About Us</a></li> -->
<li>
<a routerLink="#">About Us</a>
<div class="sub-menu">
<ul>
<li>
Gallery
</li>
<li>
Testimonials
</li>
<li>
Blogs
</li>
</ul>
</div>
</li>
</div>
It's due to margin-top: 15px for submenu. In these 15px you go away from parent LI -> li:hover isn't applied -> submenu is hidden.
Change it for padding, or set margin to first submenu li. Below is a solution with padding-top: 15px.
.navbar-ul > li {background: red; position: relative;}
.sub-menu{
display: none;
}
.sub-menu ul li{
margin: 15px;
width: 120px;
padding: 15px;
}
.navbar-header ul li:hover .sub-menu{
display: block !important;
position:absolute;
background: yellow;
padding-top: 15px; /* padding-top instead of margin-top */
margin-left: -15px;
}
.sub-menu ul:hover {
display: block !important;
}
.navbar-header ul li:hover .sub-menu ul{
display: block;
margin: 10px;
-o-transition:.3s ease;
-ms-transition:.3s ease;
-moz-transition:.3s ease;
-webkit-transition:.3s ease;
transition:.3s ease;
outline: none;
}
.sub-menu ul li:hover {
display: block;
background: #f69220;
}
.sub-menu ul li a{
color: black;
}
.navbar-header ul li:hover .sub-menu ul li{
display: block !important;
color: black ;
width: 150px;
padding: 5px;
border-radius: 0;
text-align: center;
}
<div class="navbar-header" style="padding: 0; margin: 0; ">
<ul class="navbar-ul">
<li> <a routerLink="/home"><img src="" class="navbar-logo" alt=""></a>
</li>
<!-- logo -->
<!-- <li><a routerLink="/home">Home</a></li> -->
<!-- <li><a routerLink="/aboutus">About Us</a></li> -->
<li>
<a routerLink="#">About Us</a>
<div class="sub-menu">
<ul>
<li>
Gallery
</li>
<li>
Testimonials
</li>
<li>
Blogs
</li>
</ul>
</div>
</li>
</div>

I need help in fixing my drop down menu from moving when showing <li>

The Problem:
Look at Offers and the li:
After putting position: absolute
Current vs What I want to achieve
How to make my drop down menu so that when I hover on "Offers" the text doesn't move to the left? I would also like to decrease the width of the li as it is too big for me.
I have tried changing the display: property and putting spaces before and after the word "Offers" in HTML. The spaces worked but I didnt like it because the Offers will just look like having more space than the other options.
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul li ul li {
display: none; /*So li dont show up unless hover */
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
I want to dropdown menu to not move when the li is shown in the Offers. And I would like to decrease the width of black background of the li
That's because the sub menu is taking a place and make its parent li wider.
A possible solution is to set the ul child position: absolute so it will not take a place.
Like this:
.menu ul ul {
position: absolute;
}
Live example:
body {
background: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg) 0 0;
background-size: cover;
}
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
position: relative;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul ul {
position: absolute;
width: 100%;
}
.menu ul li ul li {
display: none;
/*So li dont show up unless hover */
}
.menu ul li ul li a {
padding: 0;
text-align: center;
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
The problem lies with the min-content size of the list items in the drop down, which are larger than the size of the parent list items in the top menu.
e.g. 'packages' renders at 120px whereas 'offers' is 98px.
The simplest solution is to set a max-width for all the list items based on the max-content size of the longest word (not very dynamic though).
Otherwise, use position:absolute to layout the sub menu as in this example:
https://codepen.io/skippingredpanda/pen/xNrxVg
Is simple, use:
.menu li { position: relative; } .menu li ul { position: absolute; top: your horizontal nav height; left: 0;}
And also you have a mistake in code, must be like this:
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>
Link 3
<ul>
<li>SubLink 1</li>
<li>SubLink 2</li>
<li>SubLink 3</li>
<li>SubLink 4</li>
</ul>
</li>
<li>Link 4</li>
</ul>
ul li {position: relative;}
ul li ul {position: absolute; display: none;}
ul li:hover ul {display: block;}

Making a CSS Drop-down Menu Responsive

I have got a CSS Drop-down menu on a website that I want to make responsive using CSS media queries, but it doesn't respond at certain breakpoints. Am using width and max-width attributes to make it respond but it fails. Please Assist?
HTML
.navbar{
width:100%;
max-width:1000px;
text-align:center;
margin-top:-8px;
margin-bottom:23px;
margin-left:160px;
}
.menu ul{
/*Removes bullets*/
list-style:none;
}
.menu ul .active{
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(red 20%, green); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(red 20%, green); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(red 20%, green); /* For Firefox 3.6 to 15 */
background: linear-gradient(red 20%, green); /* Standard syntax */
background: linear-gradient(red 20%, green); /* Standard syntax */
}
/*Styles each list within ul*/
.menu ul li{
background-color:green;
border:1px solid #ffffff;
width:100%;
max-width:173px;
height:35px;
line-height:35px;
margin:auto;
text-align:center;
/*Makes the list dispaly in a horizontal maneer*/
float:left;
position:relative;
border-radius:8px;
font: 15px;
font-weight:regular;
}
.menu ul li a{
text-decoration:none;
color:white;
display:block;
}
.menu ul li a:hover{
background-color:red;
border-radius:8px;
}
.menu ul ul{
position:absolute;
margin-left:-40px;
display:none;
}
.menu ul li:hover >ul{
display:block;
}
.menu ul ul ul{
width:100%;
margin-left:134px;
top:0px;
}
#media only screen and (min-width: 1023px) and (max-width: 1223px) {
.navbar{
width:98%;
max-width:1000px;
}
.menu ul li{
width:98%;
max-width:173px;
height:35px;
line-height:35px;
margin:auto;
}
.menu ul ul ul{
width:98%;
margin-left:134px;
top:0px;
}
}
<div class="navbar">
<div class="menu">
<ul>
<li class="active"> Home </li>
<li> Arts & Social Sciences <span class="arrow">▼ </span>
<ul>
<li> Sociology</li>
<li> Anthropology </li>
<li> Linguistics </li>
<li> Political Science <span class="arrow"> 〉</span>
<ul>
<li> World Civilization </li>
<li> Politics of Development </li>
<li> Comparative Politics</li>
<li> Globalization </li>
</ul>
</li>
</ul>
</li>
<li> Business & Economics <span class="arrow">▼ </span>
<ul>
<li> Business Management</li>
<li> Purchasing and Supplies </li>
<li> Economics
<ul>
<li> Micro Economics </li>
<li> Inflation </li>
<li> Stock Excahange </li>
<li> Supply Chain </li>
<li> Macro-Economics </li>
</ul>
</li>
</ul>
</li>
<li> Education<span class="arrow">▼ </span>
<ul>
<li> Education(Arts)</li>
<li> Early Childhood </li>
<li> Education(Scienmce)</li>
<li> Education & Technology
<ul>
<li> Marketing </li>
<li> Supply Chain </li>
</ul>
</li>
</ul>
</li>
<li> Contact Us</li>
</ul>
</div>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<div class="bs-example">
<nav id="myNavbar" class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Menu</li>
<li>Menu</li>
<li class="dropdown">
Menu <b class="caret"></b>
<ul class="dropdown-menu">
<li>Sub-Menu</li>
<li>Sub-Menu</li>
<li>Sub-Menu</li>
<li>Sub-Menu</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</nav>
</div>
</body>
</html>
(function($) {
$.fn.menumaker = function(options) {
var cssmenu = $(this),
settings = $.extend({
format: "dropdown",
sticky: false
}, options);
return this.each(function() {
$(this).find(".button").on('click', function() {
$(this).toggleClass('menu-opened');
var mainmenu = $(this).next('ul');
if (mainmenu.hasClass('open')) {
mainmenu.slideToggle().removeClass('open');
} else {
mainmenu.slideToggle().addClass('open');
if (settings.format === "dropdown") {
mainmenu.find('ul').show();
}
}
});
cssmenu.find('li ul').parent().addClass('has-sub');
multiTg = function() {
cssmenu.find(".has-sub").prepend('<span class="submenu-button"></span>');
cssmenu.find('.submenu-button').on('click', function() {
$(this).toggleClass('submenu-opened');
if ($(this).siblings('ul').hasClass('open')) {
$(this).siblings('ul').removeClass('open').slideToggle();
} else {
$(this).siblings('ul').addClass('open').slideToggle();
}
});
};
if (settings.format === 'multitoggle') multiTg();
else cssmenu.addClass('dropdown');
if (settings.sticky === true) cssmenu.css('position', 'fixed');
resizeFix = function() {
var mediasize = 700;
if ($(window).width() > mediasize) {
cssmenu.find('ul').show();
}
if ($(window).width() <= mediasize) {
cssmenu.find('ul').hide().removeClass('open');
}
};
resizeFix();
return $(window).on('resize', resizeFix);
});
};
})(jQuery);
(function($) {
$(document).ready(function() {
$("#cssmenu").menumaker({
format: "multitoggle"
});
});
})(jQuery);
* {
margin: 0;
padding: 0;
text-decoration: none
}
body {
background: #555;
}
header {
position: relative;
width: 100%;
background: #333;
}
.logo {
position: relative;
z-index: 123;
padding: 10px;
font: 18px verdana;
color: #6DDB07;
float: left;
width: 15%
}
.logo a {
color: #6DDB07;
}
nav {
position: relative;
width: 980px;
margin: 0 auto;
}
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a,
#cssmenu #head-mobile {
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box
}
#cssmenu:after,
#cssmenu>ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0
}
#cssmenu #head-mobile {
display: none
}
#cssmenu {
font-family: sans-serif;
background: #333
}
#cssmenu>ul>li {
float: left
}
#cssmenu>ul>li>a {
padding: 17px;
font-size: 12px;
letter-spacing: 1px;
text-decoration: none;
color: #ddd;
font-weight: 700;
}
#cssmenu>ul>li:hover>a,
#cssmenu ul li.active a {
color: #fff
}
#cssmenu>ul>li:hover,
#cssmenu ul li.active:hover,
#cssmenu ul li.active,
#cssmenu ul li.has-sub.active:hover {
background: #448D00!important;
-webkit-transition: background .3s ease;
-ms-transition: background .3s ease;
transition: background .3s ease;
}
#cssmenu>ul>li.has-sub>a {
padding-right: 30px
}
#cssmenu>ul>li.has-sub>a:after {
position: absolute;
top: 22px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: ''
}
#cssmenu>ul>li.has-sub>a:before {
position: absolute;
top: 19px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: '';
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
transition: all .25s ease
}
#cssmenu>ul>li.has-sub:hover>a:before {
top: 23px;
height: 0
}
#cssmenu ul ul {
position: absolute;
left: -9999px
}
#cssmenu ul ul li {
height: 0;
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
background: #333;
transition: all .25s ease
}
#cssmenu ul ul li:hover {}
#cssmenu li:hover>ul {
left: auto
}
#cssmenu li:hover>ul>li {
height: 35px
}
#cssmenu ul ul ul {
margin-left: 100%;
top: 0
}
#cssmenu ul ul li a {
border-bottom: 1px solid rgba(150, 150, 150, 0.15);
padding: 11px 15px;
width: 170px;
font-size: 12px;
text-decoration: none;
color: #ddd;
font-weight: 400;
}
#cssmenu ul ul li:last-child>a,
#cssmenu ul ul li.last-item>a {
border-bottom: 0
}
#cssmenu ul ul li:hover>a,
#cssmenu ul ul li a:hover {
color: #fff
}
#cssmenu ul ul li.has-sub>a:after {
position: absolute;
top: 16px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: ''
}
#cssmenu ul ul li.has-sub>a:before {
position: absolute;
top: 13px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: '';
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
transition: all .25s ease
}
#cssmenu ul ul>li.has-sub:hover>a:before {
top: 17px;
height: 0
}
#cssmenu ul ul li.has-sub:hover,
#cssmenu ul li.has-sub ul li.has-sub ul li:hover {
background: #363636;
}
#cssmenu ul ul ul li.active a {
border-left: 1px solid #333
}
#cssmenu>ul>li.has-sub>ul>li.active>a,
#cssmenu>ul ul>li.has-sub>ul>li.active>a {
border-top: 1px solid #333
}
#media screen and (max-width:700px) {
.logo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 46px;
text-align: center;
padding: 10px 0 0 0;
float: none
}
.logo2 {
display: none
}
nav {
width: 100%;
}
#cssmenu {
width: 100%
}
#cssmenu ul {
width: 100%;
display: none
}
#cssmenu ul li {
width: 100%;
border-top: 1px solid #444
}
#cssmenu ul li:hover {
background: #363636;
}
#cssmenu ul ul li,
#cssmenu li:hover>ul>li {
height: auto
}
#cssmenu ul li a,
#cssmenu ul ul li a {
width: 100%;
border-bottom: 0
}
#cssmenu>ul>li {
float: none
}
#cssmenu ul ul li a {
padding-left: 25px
}
#cssmenu ul ul li {
background: #333!important;
}
#cssmenu ul ul li:hover {
background: #363636!important
}
#cssmenu ul ul ul li a {
padding-left: 35px
}
#cssmenu ul ul li a {
color: #ddd;
background: none
}
#cssmenu ul ul li:hover>a,
#cssmenu ul ul li.active>a {
color: #fff
}
#cssmenu ul ul,
#cssmenu ul ul ul {
position: relative;
left: 0;
width: 100%;
margin: 0;
text-align: left
}
#cssmenu>ul>li.has-sub>a:after,
#cssmenu>ul>li.has-sub>a:before,
#cssmenu ul ul>li.has-sub>a:after,
#cssmenu ul ul>li.has-sub>a:before {
display: none
}
#cssmenu #head-mobile {
display: block;
padding: 23px;
color: #ddd;
font-size: 12px;
font-weight: 700
}
.button {
width: 55px;
height: 46px;
position: absolute;
right: 0;
top: 0;
cursor: pointer;
z-index: 12399994;
}
.button:after {
position: absolute;
top: 22px;
right: 20px;
display: block;
height: 4px;
width: 20px;
border-top: 2px solid #dddddd;
border-bottom: 2px solid #dddddd;
content: ''
}
.button:before {
-webkit-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
position: absolute;
top: 16px;
right: 20px;
display: block;
height: 2px;
width: 20px;
background: #ddd;
content: ''
}
.button.menu-opened:after {
-webkit-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
top: 23px;
border: 0;
height: 2px;
width: 19px;
background: #fff;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg)
}
.button.menu-opened:before {
top: 23px;
background: #fff;
width: 19px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg)
}
#cssmenu .submenu-button {
position: absolute;
z-index: 99;
right: 0;
top: 0;
display: block;
border-left: 1px solid #444;
height: 46px;
width: 46px;
cursor: pointer
}
#cssmenu .submenu-button.submenu-opened {
background: #262626
}
#cssmenu ul ul .submenu-button {
height: 34px;
width: 34px
}
#cssmenu .submenu-button:after {
position: absolute;
top: 22px;
right: 19px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: ''
}
#cssmenu ul ul .submenu-button:after {
top: 15px;
right: 13px
}
#cssmenu .submenu-button.submenu-opened:after {
background: #fff
}
#cssmenu .submenu-button:before {
position: absolute;
top: 19px;
right: 22px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: ''
}
#cssmenu ul ul .submenu-button:before {
top: 12px;
right: 16px
}
#cssmenu .submenu-button.submenu-opened:before {
display: none
}
#cssmenu ul ul ul li.active a {
border-left: none
}
#cssmenu>ul>li.has-sub>ul>li.active>a,
#cssmenu>ul ul>li.has-sub>ul>li.active>a {
border-top: none
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id='cssmenu'>
<div class="logo">Responsive </div>
<div id="head-mobile"></div>
<div class="button"></div>
<ul>
<li class='active'><a href='#'>HOME</a></li>
<li><a href='#'>Arts And Social Science</a>
<ul>
<li>sociology</li>
<li>Anthropology</li>
<li>Linguistics</li>
<li>Linguistics</li>
<li>Political Science
<ul>
<li>World Civilization </li>
<li>Politics of Development</li>
<li>Comparative Politics</li>
<li>Globalization</li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>Business & Economics</a>
<ul>
<li> Business Management</li>
<li> Purchasing and Supplies </li>
<li> Economics
<ul>
<li> Micro Economics </li>
<li> Inflation </li>
<li> Stock Excahange </li>
<li> Supply Chain </li>
<li> Macro-Economics </li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>Education</a>
<ul>
<li> Education(Arts)</li>
<li> Early Childhood </li>
<li> Education(Scienmce)</li>
<li> Education & Technology
<ul>
<li> Marketing </li>
<li> Supply Chain </li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>Contact Us</a>
</li>
</ul>
</nav>
</header>
<section style='padding-top:20px;font:bold 44px arial;color:#68D800;'>
CSS Menu
</section>
#media only screen and (min-width: 1023px) and (max-width: 1223px)
This will execute the code between 1023px and 1223px which is really really small.
Try using only one of them at a time like this:
#media only screen and (min-width: 1023px)
or this:
#media only screen and (min-width: 1023px)
Or just increase the resolution gap, like this:
#media only screen and (min-width: 768px) and (max-width: 1223px)

CSS3 slide down menu on hover

I want to build a menu that is CSS only. No jQuery.
I've gotten this far but can't make the menu slide in from the top. Here's a fiddle (oddly enough, it doesn't look like my menu... but all the styles are there)
Some code: The HTML:
<div class="menu">
<ul>
<li class="blue"> <a style="text-decoration: none" href="/who-we-are">Who We Are</a>
</li>
<li class="red"> <a style="text-decoration: none" href="/services">Services</a>
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="orange"><a style="text-decoration: none" href="/packages">Packages</a>
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="green"><a style="text-decoration: none" href="/contact-us">Contact</a>
</li>
</ul>
</div>
And my CSS:
.menu {
float: left;
margin-top: 0px;
}
.blue, div.item.blue div {
color: #009dc4;
}
.red, div.item.red div {
color: #fe4f00;
}
.orange, div.item.orange div {
color: #ff5958;
}
.green, div.item.green div {
color: #50c402;
}
.menu ul li a {
display: block;
height: 45px;
padding-top: 18px;
}
.menu ul li a:visited {
color: inherit;
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
display: inline-block;
position: relative;
cursor: pointer;
width: 145px;
font-family: Georgia;
height: 45px;
font-size: 20px;
line-height: 22px;
font-weight: bold;
padding-left: 5px;
margin-top: 0px;
margin-right: 46px;
border-bottom: 5px solid;
z-index: 5000;
}
.menu ul li:hover {
color: #ffffff !important;
}
.menu ul li.blue:hover {
background-color: #009dc4;
border-bottom: 5px solid #009dc4;
}
.menu ul li.red:hover {
background-color: #fe4f00;
border-bottom: 5px solid #fe4f00;
}
.menu ul li.orange:hover {
background-color: #ff5958;
border-bottom: 5px solid #ff5958;
}
.menu ul li.green:hover {
background-color: #50c402;
border-bottom: 5px solid #50c402;
}
.menu ul li ul {
display: none;
opacity: 0;
visibility: hidden;
position: absolute;
top: 45px;
}
.menu ul li ul li {
display: block;
font-size: 12px;
border-bottom: none;
width: 145px;
color: #ffffff;
padding-left: 0px;
height: 34px;
line-height: normal;
position: relative;
left: -5px;
}
.menu ul li ul li a {
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
height: auto;
padding: 10px 5px;
font-size: 12px;
background-color: #4fc7c1;
-webkit-transition: all 0.1s;
-moz-transition: all 0.1s;
-ms-transition: all 0.1s;
-o-transition: all 0.1s;
transition: all 0.1s;
}
.menu ul li ul li a:hover {
background: #a3edf5;
}
.menu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.menu > ul > li:last-of-type {
margin-right: 0px;
}
If someone can just help with getting the slide down to work, I'd appreciate it.
Unfortunately there is no way to animate height:0 to height:auto with CSS (as of CSS3). However there is a workaround using max-height documented here: http://css3.bradshawenterprises.com/animating_height/
With that logic I have created a simple example from your JS fiddle. All it does is set the css style max-height:0 on the drop-down <ul> element, some transitions for the max-height css attribute and then a large max-height value on menu hover.
Unfortunately the max-height must be hard-coded (cannot be auto) so we are limited here; but if you are confident that your menus will never exceed say 500px then you would simply put 500px.
Here's the fiddle:
http://jsfiddle.net/6ame5wcu/4/
All you need to do is to set max-height:0; and overflow:hidden; then add a transition on it like this:
.menu ul li ul {
max-height:0em;
overflow:hidden;
position: absolute;
top: 45px;
transition:max-height .9s ease
}
on :hover set a max-height ie max-height:600px;
.menu ul li:hover ul {
max-height:600px;
}
DEMO
Full code:
<div class="menu">
<ul>
<li class="blue"> Who We Are
</li>
<li class="red"> Services
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="orange">Packages
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="green">Contact
</li>
</ul>
</div>
css
a{text-decoration: none}
.menu {
float: left;
margin-top: 0px;
}
.blue, div.item.blue div {
color: #009dc4;
}
.red, div.item.red div {
color: #fe4f00;
}
.orange, div.item.orange div {
color: #ff5958;
}
.green, div.item.green div {
color: #50c402;
}
.menu ul li a {
display: block;
height: 45px;
padding-top: 18px;
}
.menu ul li a:visited {
color: inherit;
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
display: inline-block;
position: relative;
cursor: pointer;
width: 145px;
font-family: Georgia;
height: 45px;
font-size: 20px;
line-height: 22px;
font-weight: bold;
padding-left: 5px;
margin-top: 0px;
margin-right: 46px;
border-bottom: 5px solid;
z-index: 5000;
}
.menu ul li:hover {
color: #ffffff !important;
}
.menu ul li.blue:hover {
background-color: #009dc4;
border-bottom: 5px solid #009dc4;
}
.menu ul li.red:hover {
background-color: #fe4f00;
border-bottom: 5px solid #fe4f00;
}
.menu ul li.orange:hover {
background-color: #ff5958;
border-bottom: 5px solid #ff5958;
}
.menu ul li.green:hover {
background-color: #50c402;
border-bottom: 5px solid #50c402;
}
.menu ul li ul {
max-height:0em;
overflow:hidden;
position: absolute;
top: 45px;
transition:max-height .9s ease
}
.menu ul li:hover ul {
max-height:600px;
}
.menu ul li ul li {
display: block;
font-size: 12px;
border-bottom: none;
width: 145px;
color: #ffffff;
padding-left: 0px;
height: 34px;
line-height: normal;
position: relative;
left: -5px;
}
.menu ul li ul li a {
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
height: auto;
padding: 10px 5px;
font-size: 12px;
background-color: #4fc7c1;
-webkit-transition: all 0.1s;
-moz-transition: all 0.1s;
-ms-transition: all 0.1s;
-o-transition: all 0.1s;
transition: all 0.1s;
}
.menu ul li ul li a:hover {
background: #a3edf5;
}
.menu > ul > li:last-of-type {
margin-right: 0px;
}

Can't get vertical submenu to display under corresponding horizontal navigation

Hi I am having trouble getting my vertical submenu to align directly under the parent horizontal menu. I only want the submenus to appear when they are hovered over. I have probably over complicated the entire CSS for myself. Any help would we very much appreciated
Here is the HTML code
<div id="nav_bar">
<ul>
<li>Home </li>
<li> About Us </li>
<li> Training
<ul>
<li> Funded Training</li>
<li> Traineeships</li>
<li> Fee for Service</li>
<li> Enterprise Specific Skill Sets</li>
<li> RPL Assessment</li>
<li> International Training</li>
</ul>
</li>
<li>
Employers
<ul>
<li> Existing Workers</li>
<li> New Workers</li>
</ul>
</li>
<li>Contact Us </li>
<li>Links</li>
</ul>
</div>
Here is the CSS
#nav_bar {
font-family: Verdana, Helvetica, Arial, sans-serif, serif;
font-size:1.2em;
font-weight:bold;
float: left;
height: 28px;
width: 689px;
margin-top: 40px;
margin-right: 20px;
margin-bottom: 0px;
margin-left: 10px;}
#nav_bar ul {
list-style-type:none;
margin:0px;
padding:0px;
overflow:hidden;}
#nav_bar li a:link, #nav_bar li a:visited {
float:left;
color: #000;
text-decoration: none;
display:block;
width: 106px;
text-align:center;
padding: 4px;
}
#nav_bar li a:hover, #nav_bar li a:active {
color: #FFF;
background-color: #184B8D;
}
#nav_bar li ul {
display: none;
position:absolute;
}
#nav_bar li ul a:link, #nav_bar li ul a:visited {
color:#000;
text-decoration:none;
display:inline-block;
width:auto;
text-align:center;
padding:4px;
}
#nav_bar li ul a:hover, #nav_bar li ul a:active {
display:block;
position: absolute;
}
#nav_bar li:hover ul {
display:block;
clear:both;
}
hey i can give example that i make refer this :)
add a class to the sub menu and apply style as follows
wish you good luck (Y)
<h2>Dropdown menu example</h2>
<nav class="cf">
<nav class="cf">
<ul class="topmenu">
<li>Home</li>
<li>Products
<ul class="submenu">
<li>Laptops</li>
<li>Tablets</li>
<li>Smartphones</li>
<li>Accessories</li>
</ul>
</li>
<li>Blog
<ul class="submenu">
<li>Recent articles</li>
<li>Archives</li>
<li>Hall of fame</li>
</ul>
</li>
<li>About</li>
<li>Contact
<ul class="submenu">
<li>Customer service</li>
<li>Register</li>
<li>Technical support</li>
</ul>
</li>
</ul>
</nav>
</nav>
CSS
/*micro-clearfix by Nicolas Gallagher http://nicolasgallagher.com/micro-clearfix-hack/*/
/* For modern browsers */
.cf:before, .cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
/* For IE 6/7 (trigger hasLayout) */
.cf {
zoom:1;
}
/*horizontal menu styles*/
nav {
background: #916A31;
height: 2.3em;
}
ul, li {
margin: 0;
padding: 0;
list-style: none;
float: left;
}
ul {
background: #D5973C;
height: 2em;
width: 100%;
}
li {
position: relative;
}
li a {
display: block;
line-height: 2em;
padding: 0 1em;
color: white;
text-decoration: none;
}
li a:hover, .topmenu li:hover > a {
background: #916A31;
height: 2em;
padding-top: .3em;
position: relative;
top: -.3em;
border-radius: .3em .3em 0 0;
}
.current, a:hover.current, .topmenu li:hover a.current {
background: #AD9B7F;
color: #eee;
padding-top: .3em;
border-radius: .3em .3em 0 0;
position: relative;
top: -.3em;
border-bottom: .3em solid #917F63;
cursor: default;
}
/*dropdown menu styles*/
ul.submenu {
float: none;
background: #916A31;
width: auto;
height: auto;
position: absolute;
top: 2em;
left: -9000em;
max-height: 0;
-moz-transition:max-height 0.5s ease-in-out;
-webkit-transition:max-height 0.5s ease-in-out;
-o-transition:max-height 0.5s ease-in-out;
transition:max-height 0.5s ease-in-out;
overflow: hidden;
}
ul.submenu li {
float: none;
}
.topmenu li:hover ul {
left: 0;
max-height: 10em;
}
ul.submenu li a {
border-bottom: 1px solid white;
padding: .2em 1em;
white-space: nowrap;
}
ul.submenu li:last-child a {
border-bottom: none;
}
ul.submenu li a:hover {
background: #D5973C;
height: 2em;
padding-top: .2em;
top: 0;
border-radius: 0;
}