This is a .header class with a background image, and navigation in the tag. What I am
trying to do is separate the background image from .header and place it in a new div (that will
go behind the navigation, but keep the same position as is) so I can
add some filters and customise it further.
<style>
.header {
float: left;
height: 300px;
width: 100%;
margin-top: 2%;
-webkit-border-top-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
background-image: url(../5898169717_6f4b2a3515_b.jpg);
background-position: center center;
background-repeat: no-repeat;
background-size: auto;
background-color: #91918e;
}
.header .nav-header { margin-top: 15px; padding-left: 30px; padding-right: 50px; }
.header .nav-header #navigation {
float: left;
position: relative;
}
.header .nav-header #navigation li {
position: relative;
list-style: none;
display: inline-block;
margin-top: 5px;
}
.header .nav-header #navigation li a {
padding: 0 inherit;
padding-left: 10px;
padding-right: 10px;
display: inline-block;
font-family: 'Open Sans', Arial, Helvetica, sans-serif;
text-shadow: 1px 1px 2px #242526, 0 0 1em #242526, 0 0 0.2em #242526;
text-decoration: none;
font-size: 14px;
font-weight: 700;
color: white;
text-align: left;
transition-property: color;
transition-duration: 100ms;
transition-timing-function: linear;
-webkit-transition-property: color;
-webkit-transition-duration: 100ms;
-webkit-transition-timing-function: ease-out;
-moz-transition-property: color;
-moz-transition-duration: 100ms;
-moz-transition-timing-function: ease-out;
-o-transition-property: color;
-o-transition-duration: 100ms;
-o-transition-timing-function: ease-out;
-ms-transition-property: color;
-ms-transition-duration: 100ms;
-ms-transition-timing-function: ease-out;
}
.header .nav-header #navigation li a:last-child {}
.header .nav-header #navigation li:hover .main { color: #f0b92d;}
/** Dropdown **/
.header .nav-header #navigation li .sub-nav-wrapper {
display: block;
position: absolute;
z-index: 30;
margin-left: -16px;
}
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav {
width: 150px;
margin-top: 10px;
background: white;
border-top: 1px solid #91918e;
box-shadow: 0 1px 2px #91918e;
-moz-box-shadow: 0 1px 2px #91918e;
-webkit-box-shadow: 0 1px 2px #91918e;
}
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav:first-child { border: none; }
.header .nav-header #navigation li:hover .sub-nav-wrapper { display: block; }
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav li {
list-style: none;
display: block;
margin: 0;
padding: 0;
text-align: left;
border-bottom: 1px solid #91918e;
}
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav li:last-child { border: none; }
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav li a {
display: block;
color: #242526;
text-decoration: none;
text-shadow: 1px 1px 2px white, 0 0 1em white, 0 0 0.2em white;
padding: 11px 20px;
font-size: 12px;
font-weight: 600;
box-shadow: inset 0 0 2px rgba(255,255,255,1.0);
-moz-box-shadow: inset 0 0 2px rgba(255,255,255,1.0);
-webkit-box-shadow: inset 0 0 2px rgba(255,255,255,1.0);
}
.header .nav-header #navigation li .sub-nav-wrapper .sub-nav li:hover {
background: #dcdbd2;
}
.header .nav-header a, #navigation li .sub-nav-wrapper .sub-nav li { }
.header .nav-header #navigation li .sub-nav-wrapper {
pointer-events: none;
opacity: 0;
filter: alpha(opacity=0);
top: 0;
}
.header .nav-header #navigation li:hover .sub-nav-wrapper {
pointer-events: auto;
opacity: 1;
filter: alpha(opacity=100);
top: 15px;
}
</style>
<section class="header">
<nav class="nav-header">
<ul id="navigation">
<li>
Home
</li>
<li>
Portfolio
<div class="sub-nav-wrapper"><ul class="sub-nav">
<li>Graphics</li>
<li>Web</li>
<li>Print</li>
</ul></div>
</li>
<li>
Services
<div class="sub-nav-wrapper"><ul class="sub-nav">
<li>Web Design</li>
<li>SEO</li>
<li>Content Writing</li>
</ul></div>
</li>
<li>
Technology
<div class="sub-nav-wrapper"><ul class="sub-nav">
<li>JavaScript</li>
<li>HTML/CSS</li>
<li>Drupal</li>
<li>Joomla</li>
<li>Wordpress</li>
<li>MySQL</li>
<li>Oracle</li>
</ul></div>
</li>
<li>
About
<div class="sub-nav-wrapper"><ul class="sub-nav">
<li>Location</li>
<li>History</li>
<li>Jobs</li>
<li>Awards</li>
</ul></div>
</li>
<li>
Contact
</li>
</ul>
</nav>
</section>
You're going to need to add a child to the .header element with a z-index: -1, and make sure the .header has the CSS position: relative;
Here's a working jsfiddle of your code working the way you want.
To your markup, as the first child of .header I added:
<div class="inner-header"></div>
And to your CSS, I added at the bottom:
.header {
background-image: none;
background-color: transparent;
position: relative;
}
.inner-header {
background-image: url('http://upload.wikimedia.org/wikipedia/commons/7/7d/Haeckel_Siphoneae.jpg');
background-size: 100% auto;
-webkit-border-top-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: -1;
}
How about this: http://jsfiddle.net/Xm5BE/
Here is the HTML:
<header>
<div class="nav">
<ul>
<li>Link 1</li>
<li>Link 1</li>
<li>Link 1</li>
<li>Link 1</li>
</ul>
</div>
<div class="header">This is the header bg div</div>
</header>
and the CSS:
header { background:black ;
width:100% ;
height:200px ;
position:relative ;
}
.header { position:absolute ;
left:0 ;
top:0 ;
width:100% ;
height:200px ;
background:blue ;
z-index:100 ;
}
.nav { width:100% ;
height:28px ;
background:yellow ;
position:relative ;
top:120px ;
z-index:500 ;
}
.nav ul { margin-left:0 ;
padding-left:0 ;
list-style-type:none ;
text-align:center ;
}
.nav li { display:inline ;
}
.nav li a { padding:0px 8px ;
line-height:28px ;
font-size:14px ;
font-family:arial ;
}
Related
NOTE: THE NAVBAR IS NOT IN BOOTSTRAP
Okay, so, when I hover over my "More" button, it displays dropdown content but it just suddently appears and when I move my mouse somewhere else it suddently disappears. What I want, is to make the dropdown content appear through a transition or something like that. Here is my code:
<nav>
<ul>
<li>Home</li>
<li>Earn Coins</li>
<li>Get Rewards</li>
<li>Referrals</li>
<li>Vouchers</li>
<li><div class="dropdownd">
More
<i class="fa fa-caret-down"></i>
<div class="dropdown-contentd">
<a class="dropdowncontentn" href="leaderboard.php">Leaderboard</a>
<a class="dropdowncontentn" href="partnerships.php">Partnerships</a>
<a class="dropdowncontentn" href="contact.php">Contact us</a>
<a class="dropdowncontentn" href="socialmedia.php">Social Media</a>
<a class="dropdowncontentn" href="settings.php">Settings</a>
</div>
</div> </li>
<li>
<a href="#">
<i class="fa fa-bars"></i>
</a>
</li>
<li class="thum" style="float:right;margin-right:25px;">
<a onClick="navbar_coins_refresh.php" href="#" class="coinsnumber"><?php include 'navbar_coins.php'; ?></a>
</li>
</ul>
</nav>
# CSS #
* {
box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav ul li a {
color: #FFF;
text-decoration: none;
font-size: 16px;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
padding: 15px;
font-family: Ubuntu;
}
nav ul li a:hover {
text-decoration: none;
color: #444;
}
nav ul li a.coinsnumber:hover {
text-decoration: none;
color: white;
}
.dropdown-contentd {
display: none;
position: absolute;
top: 49px;
background-color: royalblue;
color: #FFF;
min-width: 160px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
z-index: 1;
/*border: 1px solid black;*/
margin: 0;
padding: 0;
padding-top: 10px;
padding-bottom: 10px;
transition: all .3s ease;
}
.dropdown-contentd a {
float: none;
color: black;
padding: 12px 16px;
color: #ffffff;
text-decoration: none;
display: block;
text-align: left;
transition: all .3s ease;
background-color: royalblue;
}
.dropdown-contentd a:hover {
color: #444;
}
.dropdownd:hover .dropdown-contentd {
display: block;
}
/* End General */
/* Start Navbar */
nav ul {
background-color: royalblue;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
nav ul > li {
padding-left: 20px;
padding-right: 20px;
padding: 15px;
display: inline-block;
transition: all .3s ease;
margin-left: -5px
}
nav ul > ol {
position: absolute;
top: 49px;
right: 0;
background: #333;
text-align: center;
list-style: none;
display: none
}
nav ul > ol > li {
width: 100vw;
color: #FFF;
margin: 0;
padding: 0;
padding-top: 10px;
padding-bottom: 10px;
transition: all .3s ease;
}
nav ul > ol > li:hover a {
margin: 20px;
}
nav ul > ol > li:hover {
background: #000;
cursor: pointer
}
nav ul input {
opacity: .7;
padding: 5px;
float: right;
display: none
}
/* Start Menue Right */
/* Start Media Query */
#media screen and (max-width:950px){
nav ul > li:not(:first-child) {
display:none;
}
nav ul > li:nth-last-of-type(2) {
display: inline-block;
}
nav ul > li:last-of-type {
display: inline-block;
}
}
#media screen and (min-width:950px) {
nav ul > ol > li {
display:none
}
nav ul > li:nth-last-of-type(2) {
display: none
}
}
.dropdowncontentn {
background-color: royalblue;
}
nav {
z-index: 1;
position: fixed;
right: 0;
left: 0;
top: 0;
}````
It's common question. You have to use max-height transition, not just height. Check here How can I transition height: 0; to height: auto; using CSS?
Hey i am having a bit of an issue. The right side of my nav when i hover over it moves the drop down menu a little more to the right. Every other nav is position to its absolute position...
nav {
padding-left: 5px
}
nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}
nav .main-nav > ul {
list-style-type: none;
}
nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
padding: 5px;
height: 80px;
margin: 5px;
align-content:center;
}
nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 5px 0;
}
nav .main-nav ul a {
text-align: center;
font-weight: 700;
font-size: 15px;
color: #84827d;
text-shadow: 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}
nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li .dropdown {
}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
top: 50px;
}
nav .main-nav .dropdown-content a {
font-size: 8px;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}
nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}
nav .main-nav ul.left {
float: left;
margin-left: 5px;
}
.dropdown-content ul {
padding: 0;
width: auto !important;
display: flex;
flex-direction: column;
}
.dropdown-content ul li {
height: auto !important;
position: relative;
}
.dropdown-content ul li:hover > .dropdown-content-second {
display: block;
}
.dropdown-content-second {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
min-width: 30px;
top: 0px;
margin-top: -1px;
margin-left: 1px;
left: 100%;
}
.dropdown-content-second ul li {
position: relative;
}
nav .main-nav ul.right {
float: right;
margin-right: 25px;
}
Here is my html, thank you in advance. I've been picking my brains out to figure out why but i cant seem to manage. please help.
<nav>
<div class="main-nav">
<ul class="left">
<li>Home</li>
<li class="dropdown"> Gods
<div class="dropdown-content">
<ul>
<li> Titans
<div class="dropdown-content-second">
<ul>
<li> Hades </li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="dropdown"> Goddesses
<div class="dropdown-content">
<ul>
<li> Olympians
<div class="dropdown-content-second">
<ul>
<li> Hera </li>
</ul>
</div>
</li>
<li> Other Goddesess
<div class="dropdown-content-second">
<ul>
<li> Gaera </li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul>
<div class="play-now"></div>
<ul class="right">
<li class="dropdown"> Heroes
<div class="dropdown-content">
<ul>
<li> Achillies </li>
<li> Theseus </li>
</ul>
</div>
</li>
<li class="dropdown"> Myths
<div class="dropdown-content">
<ul>
<li> THE ADVENTURES OF PERSEUS </li>
</ul>
</div>
</li>
<li>Contact Us</li>
</ul>
</div>
</nav>
Try this CSS
nav {
padding-left: 5px
}
nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}
nav .main-nav > ul {
list-style-type: none;
}
nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
padding: 5px;
height: 80px;
margin: 5px;
align-content:center;
}
nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 5px 0;
}
nav .main-nav ul a {
text-align: center;
font-weight: 700;
font-size: 15px;
color: #84827d;
text-shadow: 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}
nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li.dropdown {
position: relative;
}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
top : 35px;
}
nav .main-nav .dropdown-content a {
font-size: 8px;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}
nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}
nav .main-nav ul.left {
float: left;
margin-left: 5px;
}
.dropdown-content ul {
padding: 0;
width: auto !important;
display: flex;
flex-direction: column;
}
.dropdown-content ul li {
height: auto !important;
position: relative;
}
.dropdown-content ul li:hover > .dropdown-content-second {
display: block;
}
.dropdown-content-second {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
min-width: 30px;
top: 0px;
margin-top: -1px;
margin-left: 1px;
left: 100%;
}
.dropdown-content-second ul li {
position: relative;
}
nav .main-nav ul.right {
float: right;
margin-right: 25px;
}
i'm trying to add an effect to a mega menu. (it's under the health tab) when you hover over a link on the left, a section on the right is supposed to appear. looking at other stack overflow examples i found that if i used a:hover + div to make the div display, that should work, but for some reason it isn't. some assistance would be greatly appreciated!
#import url("http://fonts.googleapis.com/css?family=Roboto");
/* mini reset */
.nav,
.nav a,
.nav ul,
.nav li,
.nav div,
.nav form,
.nav input {
border: none;
margin: 0;
outline: none;
padding: 0;
}
.nav a {
text-decoration: none;
}
.nav li {
list-style: none;
}
/* menu container */
.nav,
input {
font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.nav {
cursor: default;
display: inline-block;
position: relative;
z-index: 500;
}
/* menu list */
.nav > li {
display: block;
float: left;
}
/* menu links */
.nav > li > a {
background: #0a64a2;
border-left: 1px solid #0f8ee2 !important;
display: block;
color: #fcfcfc;
font-weight: bold;
height: 54px;
line-height: 54px;
padding: 0 20px;
position: relative;
text-shadow: 0 0 1px rgba(0,0,0,.35);
-webkit-transition: all .3s ease;
transition: all .3s ease;
z-index: 510;
}
.nav > li:hover > a {
background: #8cbd3a;
}
.nav > li:first-child > a {
border-left: none;
border-radius: 3px 0 0 3px;
}
/* search form */
.nav > li.nav-search > form {
border-left: 1px solid #0f8ee2;
height: 54px;
position: relative;
width: inherit;
z-index: 510;
}
.nav > li.nav-search input[type="text"] {
background: #0a64a2;
display: block;
font-weight: bold;
font-size: 14px;
float: left;
height: 54px;
line-height: 24px;
padding: 15px 0 !important;
text-shadow: 0 0 1px rgba(0,0,0,.35);
-webkit-transition: all .3s ease 1s;
transition: all .3s ease 1s;
width: 1px;
color: #ebebeb;
}
.nav > li.nav-search input[type="text"]:focus {
color: #fcfcfc;
border:none;
box-shadow: none;
}
.nav > li.nav-search input[type="text"]:focus,
.nav > li.nav-search:hover input[type="text"] {
padding: 15px 20px !important;
-webkit-transition: all .3s ease .1s;
transition: all .3s ease .1s;
min-width: 110px;
width: 60%;
color: #ebebeb;
}
.nav > li.nav-search input[type="submit"] {
background: #0a64a2 url(../img/search-icon.png) no-repeat center center;
border-radius: 0 3px 3px 0;
cursor: pointer;
display: block;
float: left;
height: 54px;
padding: 0 25px;
-webkit-transition: all .3s ease;
transition: all .3s ease;
width: 20px;
}
.nav > li.nav-search input[type="submit"]:hover {
background-color: #4b4441;
}
/* menu dropdown */
.nav > li > div {
background: #fff;
border: 1px solid #ddd;
border-radius: 0 0 3px 3px;
position: absolute;
display: block;
left: 0;
opacity: 0;
overflow: hidden;
top: 50px;
-webkit-transition: all .3s ease .15s;
transition: all .3s ease .15s;
visibility: hidden;
width: 100%;
}
.nav > li:hover > div {
opacity: 1;
overflow: visible;
visibility: visible;
}
/* menu content styles */
.nav .nav-column {
float: left;
padding: 2.5%;
width: 25%;
}
.nav .nav-column h3 {
color: #372f2b;
font-size: 14px;
font-weight: bold;
line-height: 18px;
margin: 20px 0 10px 0;
text-transform: uppercase;
}
.nav .nav-column h3.orange {
color: #ff722b;
}
.nav .nav-column li a {
color: #888;
display: block;
font-weight: bold;
line-height: 26px;
}
.nav .nav-column li a:hover {
color: #8cbd34;
}
.nav a:hover > .menuheader {
color: #8cbd3a;
}
.nav a p {
color: black;
font-weight: normal;
}
.menuheader {
font-weight: bold !important;
margin-bottom: 0px;
margin-top: 5px;
font-size: 1.2em;
line-height: 18px;
}
.nav-column.info {
width: 75%;
}
.nav-column.info a {
display: none !important;
}
.healthlink1:hover + .healthinfo1 {
display: block !important;
}
<link href="https://dhbhdrzi4tiry.cloudfront.net/cdn/sites/foundation.min.css" rel="stylesheet"/>
<div class="menu-wrapper">
<ul class="nav">
<li>item</li>
<li>item</li>
<li>Health
<div>
<div class="nav-column left">
<ul>
<li class="healthlinks">
Asthma
Birth Defects
Cancer
Carbon Monoxide Poisoning
COPD
Heart Attacks
Heat Related Illness
Lead Poisoning
Oral Health
Reproductive Outcomes
</li>
</ul>
</div><!-- /nav-column -->
<div class="nav-column info left">
<ul>
<li>
Asthma info
Birth Defects info
Cancer info
Carbon Monoxide Poisoning info
COPD info
Heart Attacks info
Heat Related Illness info
Lead Poisoning info
Oral Health info
Reproductive Outcomes info
</li>
</ul>
</div><!-- /nav-column -->
</div>
</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
.nav-column.info a {
display: none !important;
}
Issue with display: none !important;
Just remove it from css style and right div will be displayed.
https://jsfiddle.net/cyhog5ra/
ok so i found foundation 6 and it does exactly what i needed so to help anyone else who has this problem here's something that works!`
$(document).ready(function() {
$(document).foundation();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/css/foundation.css">
<div class = "row collapse">
<div class = "medium-3 columns">
<ul class = "tabs vertical" data-tabs id = "tabs_example">
<li class = "tabs-title is-active">text 1</li>
<li class = "tabs-title">text 2</li>
<li class = "tabs-title">text 3</li>
<li class = "tabs-title">text 4</li>
<li class = "tabs-title">text 5</li>
</ul>
</div>
<div class = "medium-9 columns">
<div class = "tabs-content vertical" data-tabs-content = "tabs_example">
<div class = "tabs-panel is-active" id = "tab1">
<p>First text</p>
</div>
<div class = "tabs-panel" id = "tab2">
<p>Second text</p>
</div>
<div class = "tabs-panel" id = "tab3">
<p>Third text</p>
</div>
<div class = "tabs-panel" id = "tab4">
<p>Fourth text</p>
</div>
<div class = "tabs-panel" id = "tab5">
<p>Five text</p>
</div>
</div>
</div>
`
Could someone explain to me why navigating away from the main menu item causes the sub-menu to vanish? And possibly provide a fix. My google-foo skills are below par this morning. Thanks all.
CSS:
body, html{
margin: 0;
}
.content{
padding: 30px;
}
.nav-main{
width: 100%;
background-color: #222;
height: 70px;
color: #fff;
}
.nav-main > ul{
margin: 0;
padding: 0;
float: left;
list-style-top: none;
}
.nav-main > ul > li {
float: left;
}
.nav-item {
display: inline-block;
padding: 15px 20px;
height: 40px;
line-height: 40px;
color: #fff;
text-decoration: none;
}
.nav-item:hover{
background-color: #444;
}
.nav-content{
position: absolute;
top: 70px;
overflow: hidden;
background-color: #222; /* same color as main nav*/
max-height: 0; /*will not display if .nav-content no padding */
}
.nav-content a{
color: #fff;
text-decoration: none;
}
.nav-content a:hover{
text-decoration: underline;
}
.nav-sub{
padding: 20px;
}
.nav-sub ul{
padding: 0;
margin: 0;
list-style-type: none;
}
.nav-sub > ul > li{
display: inline-block;
}
.nav-sub ul li a{
padding: 5px 0;
}
.nav-item:focus{
background-color: #444; /*remove if click focus not necessary*/
}
.nav-item:hover ~ .nav-content{
max-height: 400px;
-webkit-transition:max-height 0.6s ease-in;
-moz-transition:max-height 0.6s ease-in;
transition:max-height 0.6s ease-in;
}
HTML:
<body>
<nav class="nav-main">
<ul>
<li>
first
<div class="nav-content">
<div class="nav-sub">
<ul>
<li>this is a thing</li>
<li>this is a thing 2</li>
</ul>
</div>
</div>
</li>
<li>
second
</li>
<li>
third
</li>
</ul>
</nav>
<div class="content">this is content</div>
</body>
I have changed:
.nav-item:hover ~ .nav-content{
To
nav > ul > li:hover > .nav-content{
And now it's working - example:
https://jsfiddle.net/saxkayv2/
I am looking for help on this navigation bar, I need it to be able to drop down while keeping the other items of the navigation bar in place. I have looked through all of the other submissions and still didn't find anything that helped. Here is the code and example.
http://jsfiddle.net/doctor_turkey/G2xfz/
<html>
<style>
#div5 {
background-color: black;
-webkit-box-shadow: 0px 0px #000000;
box-shadow:0px 5px 5px #5B5454;
width: 100%;
clear: both;
margin-left: -1%;
margin-right:-1%;
padding-left:1%;
padding-right:1%;
}
#div5 ul{
margin: 0 0 0 60px;
padding: 0px;
list-style: none;
}
#div5 ul li{
display: inline;
-webkit-box-shadow: 0px 0px #000000;
box-shadow: 0px 0px #000000;
position:relative;
}
#div5 ul li a{
float: left;
width: 15%;
height: 20px;
margin-top: -5px;
margin-bottom: 10px;
padding: 0;
font-size: 15px;
font-weight: none;
text-align: center;
text-decoration: none;
color: black;
border-left: 1px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
}
#div5 ul li .firstmenu{
border-left: 2px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
-webkit-box-shadow: 0px 0px;
box-shadow: 0px 0px;
}
#div5 ul li .smallmenuend{
border-left: 1px solid #CCCCCC;
border-right: 2px solid #CCCCCC;
}
/* HOVER MENU TEST*/
#div5 li ul {
float: left;
left: 0;
opacity: 0;
position:relative;
display:none;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#div5 li:hover ul {
opacity: 1;
/* top: 50px;*/
display:block;
float: left;
color:black;
clear:left;
display:block;
margin-left:20%;
}
#div5 li ul li {
clear:left;
color:black;
display:block;
width:100%;
}
#div5 li ul li a{
width:100%;
}
#div5 li ul a:hover {
background: #bbb;
}
</style>
<div id="div5" class="fluid">
<p align="center">
<div align="center">
<ul>
<li> One</li>
<li> Two
<ul>
<li> Test 1 </li>
<li> Test 2 </li>
</ul>
</li>
<li><a href="#" >Three</a></li>
<li> Four </li>
<li>Five</li>
<li >Six</li>
</ul>
</div>
</p>
</div>
Your code needs a lot of work - it is a soup of unnecessary markup and styles.
Here's a cleaned up version of this navigation bar. You are welcome to study this code and optimize yours.
HTML:
<ul id = "nav">
<li>Home</li>
<li>Energy
<ul>
<li>Test 1</li>
<li>Test 2</li>
</ul>
</li>
<li>Account</li>
<li>Contact</li>
<li>Services</li>
<li >Solutions</li>
</ul>
CSS:
* {
margin: 0;
padding: 0;
}
body {
background-color: #eee;
}
#nav {
list-style-type: none;
display: table;
min-width: 610px;
margin: 0 auto;
background-color: #fff;
text-align: center;
}
#nav > li {
display: inline-block;
position: relative;
}
#nav ul {
list-style-type: none;
background-color: #5f6975;
position: absolute;
min-width: 100%;
}
#nav li a {
font: normal 15px/1 Sans-Serif;
text-decoration: none;
color: #4b545f;
display: block;
padding: 10px 20px;
text-align: left;
white-space: nowrap;
}
#nav ul a {
color: #fff;
}
#nav ul > li + li {
border-top: 1px solid #6b727c;
}
#nav li:hover {
background-color: #4b545f;
}
#nav > li:hover > a {
color: #fff;
}
#nav ul {
display: none;
}
#nav li:hover > ul {
display: block;
}
And, a fiddle: http://jsfiddle.net/bE2D2/.