I have the following navigation which I have made responsive by using display:flex:
#header-nav { display: flex; flex-grow: 1; background: #707276; background: rgba(112,114,118,0.75); }
#header-nav .nav-item { display: flex; flex-grow: 1; flex-basis: 0; }
#header-nav .nav-link { display: block; color: #ffffff; display: flex; flex-grow: 1; justify-content: center; align-items: center; white-space: nowrap; }
#header-nav > .nav-item > .nav-link { box-sizing: border-box; text-transform: uppercase; text-decoration: none; padding: 15px 0; position: relative; transition: color 0.5s ease-in-out; font-size: 115.385%; font-family: VegurRegular; }
#header-nav > .nav-item > .nav-link:hover { color: #000000; }
#header-nav > .nav-item > .nav-link:after { content: ''; display: block; position: absolute; bottom: 0; left: 0; right: 0; height: 5px; opacity: 0; transition: opacity 0.5s ease-in-out; background-color: #36383a; }
#header-nav > .nav-item > .nav-link:hover:after { opacity: 0.8; }
#header-nav .home { flex-grow: 0; flex-basis: auto; padding: 0 50px; }
#header-nav .nav-item.home > .nav-link { display: block; }
#header-nav .nav-item.home > .nav-link:after { display: none; }
<ul id="header-nav">
<li class="nav-item home">
<a href="/" class="nav-link">
<span id="logo-text" class="sprite">Logo</span>
</a>
</li>
<li class="nav-item">
Shop
</li>
<li class="nav-item">
Tiling Ideas
</li>
<li class="nav-item">
Advice
</li>
<li class="nav-item">
Find a Retailer
</li>
</ul>
As you can see, the logo stays the same width, whilst the rest is responsive. But if you use the fullpage link and then make the width of the screen smaller, you will see the links start to overlap each other. Is there any way to stop this from happening using flex?
I know I can find a route with using display table that would achieve the same thing but I would prefer to use display flex.
Try removing the white-space: nowrap; as it is is inherently not responsive.
#header-nav {
display: flex;
flex-grow: 1;
background: #707276;
background: rgba(112, 114, 118, 0.75);
}
#header-nav .nav-item {
display: flex;
flex: 1;
}
#header-nav .nav-link {
color: #ffffff;
display: flex;
flex-grow: 1;
text-align: center;
justify-content: center;
align-items: center;
align-content: center;
}
#header-nav > .nav-item > .nav-link {
box-sizing: border-box;
text-transform: uppercase;
text-decoration: none;
padding: 15px 0;
position: relative;
transition: color 0.5s ease-in-out;
font-size: 115.385%;
font-family: VegurRegular;
}
#header-nav > .nav-item > .nav-link:hover {
color: #000000;
}
#header-nav > .nav-item > .nav-link:after {
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 5px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
background-color: #36383a;
}
#header-nav > .nav-item > .nav-link:hover:after {
opacity: 0.8;
}
#header-nav .home {
flex-grow: 0;
flex-basis: auto;
padding: 0 50px;
}
#header-nav .nav-item.home > .nav-link {
display: block;
}
#header-nav .nav-item.home > .nav-link:after {
display: none;
}
<ul id="header-nav">
<li class="nav-item home">
<a href="/" class="nav-link">
<span id="logo-text" class="sprite">Logo</span>
</a>
</li>
<li class="nav-item">
Shop
</li>
<li class="nav-item">
Tiling Ideas
</li>
<li class="nav-item">
Advice
</li>
<li class="nav-item">
Find a Retailer
</li>
</ul>
Alternatively, consider media queries to reduce the font size at lower screen sizes.
Related
Something on my website is bothering me.
The last menu item of my Navbar is outside it's container's background:
Here is how my CSS looks like:
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
height: 280px;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}
.nav-menu.active {
display: flex;
flex-direction: column;
align-content: flex-start;
background: #242222;
left: 0;
opacity: 1;
transition: all 0.5s ease;
z-index: 1;
}
.nav-links {
text-align: center;
padding: 2rem;
width: 100%;
display: table;
}
.nav-links:hover {
background-color: #fff;
color: #242424;
border-radius: 0;
}
.navbar-logo {
position: absolute;
top: 0;
left: 0;
transform: translate(25%, 50%);
}
.menu-icon {
display: block;
position: absolute;
top: 0;
right: 0;
transform: translate(-100%, 60%);
font-size: 1.8rem;
cursor: pointer;
}
.fa-times {
color: #fff;
font-size: 2rem;
}
.nav-links-mobile {
display: block;
text-align: center;
margin: 2rem auto;
border-radius: 4px;
width: 80%;
text-decoration: none;
font-size: 1.5rem;
background-color: transparent;
color: #fff;
padding: 14px 20px;
border: 1px solid #fff;
transition: all 0.3s ease-out;
}
.nav-links-mobile:hover {
background: #fff;
color: #242424;
transition: 250ms;
}
}
and HTML generated by a React component looks like this:
<>
<nav className='navbar'>
<div className='navbar-container'>
<Link to='/' className='navbar-logo' onClick={closeMobileMenu}>
LOGO
</Link>
<div className='menu-icon' onClick={handleClick}>
<i className={click ? 'fas fa-times' : 'fas fa-bars'} />
</div>
<ul className={click ? 'nav-menu active' : 'nav-menu'}>
<li className='nav-item'>
<Link to='/' className='nav-links' onClick={closeMobileMenu}>
Home
</Link>
</li>
<li className='nav-item'>
<HashLink to='/#wherewefly' onClick={closeMobileMenu} className='nav-links'>
Where we fly
</HashLink>
</li>
<li className='nav-item'>
<Link
to='/services'
className='nav-links'
onClick={closeMobileMenu}
>
Promotions
</Link>
</li>
<li className='nav-item'>
<Link
to='/products'
className='nav-links'
onClick={closeMobileMenu}
>
Contact
</Link>
</li>
</ul>
{button && <Button buttonStyle='btn--outline'>LOGIN</Button>}
</div>
</nav>
</>
How can I make the last menu item (Contact) be covered by the black background too?
I have tried changing the height but the menu items "follow" and are aligned to the bottom. I can't find out how to change it though.
Edited: Picture has been updated
Remove height: 280px;.
You are using flex-box so you shouldn't be setting the height or width attributes. The idea is to allow the box to be flexible to it's contents.
If you want a fixed height you should be using flex-basis attribute.
EXAMPLE
I have had to convert your react to html to demonstrate but as you can see the code you provided works as expected. This would indicate the issue lies elsewhere in code you have not provided.
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}
.nav-menu.active {
display: flex;
flex-direction: column;
align-content: flex-start;
background: #242222;
left: 0;
opacity: 1;
transition: all 0.5s ease;
z-index: 1;
}
.nav-links {
text-align: center;
padding: 2rem;
width: 100%;
display: table;
}
.nav-links:hover {
background-color: #fff;
color: #242424;
border-radius: 0;
}
.navbar-logo {
position: absolute;
top: 0;
left: 0;
transform: translate(25%, 50%);
}
.menu-icon {
display: block;
position: absolute;
top: 0;
right: 0;
transform: translate(-100%, 60%);
font-size: 1.8rem;
cursor: pointer;
}
.fa-times {
color: #fff;
font-size: 2rem;
}
.nav-links-mobile {
display: block;
text-align: center;
margin: 2rem auto;
border-radius: 4px;
width: 80%;
text-decoration: none;
font-size: 1.5rem;
background-color: transparent;
color: #fff;
padding: 14px 20px;
border: 1px solid #fff;
transition: all 0.3s ease-out;
}
.nav-links-mobile:hover {
background: #fff;
color: #242424;
transition: 250ms;
}
<nav class='navbar'>
<div clas='navbar-container'>
<a class='navbar-logo'> LOGO
</a>
<div class='menu-icon'>
<i class='fas fa-times' />
</div>
<ul class='nav-menu active'>
<li class='nav-item'>
<a class='nav-links'> Home
</a>
</li>
<li class='nav-item'>
<a class='nav-links'>
Where we fly
</a>
</li>
<li class='nav-item'>
<a class='nav-links'> Promotions
</a>
</li>
<li class='nav-item'>
<a class='nav-links'> Contact
</a>
</li>
</ul>
<Button class='btn--outline'>LOGIN</Button>
</div>
</nav>
Well, the height is fixed in the CSS, if you want it to take the height the content has you need to use "fit-content".
Blockquote
The issue could be the height of the nav-menu. please use min-hight instead. This may fix your issue
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
min-height: 280px;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}
I've been working on a navigation bar. I've got it styled the way I like, but for some reason am having issues getting submenus to work.
The code looks like:
<div id="head">
<input id="toggle" type="checkbox">
<label for="toggle" class="icon">
<div><!-- --></div>
<div><!-- --></div>
<div><!-- --></div>
</label>
<div id="nav">
<div>
<ul>
<li class="page_item page-item-8">Home</li>
<li class="page_item page-item-10 page_item_has_children">About
<ul class="children">
<li class="page_item page-item-22 page_item_has_children">Once More
<ul class="children">
<li class="page_item page-item-23 page_item_has_children">Another Sub Page
<ul class="children">
<li class="page_item page-item-25">Final Link</li>
<li class="page_item page-item-24">Something Else</li>
</ul>
</li>
</ul>
</li>
<li class="page_item page-item-21">Another Page</li>
<li class="page_item page-item-20">Subpage</li>
</ul>
</li>
<li class="page_item page-item-13 current_page_item">Shop</li>
<li class="page_item page-item-9">FAQ</li>
<li class="page_item page-item-11">Contact</li>
</ul>
</div>
</div>
</div>
The CSS looks like:
/* Toggle */
#toggle {
display: none;
}
/* Nav */
#nav li.current_page_item a {
background: #d2b48c;
border-radius: 40px;
color: #260f03;
}
#nav li a {
border-bottom: 1px solid transparent;
border-top: 1px solid transparent;
color: #fff;
display: inline-block;
font-family: 'Lato', sans-serif;
font-size: 14px;
letter-spacing: 4px;
margin: 20px;
padding: 10px 10px 10px 15px;
text-decoration: none;
text-transform: uppercase;
}
/* Media */
#media screen and (max-width: 600px) {
/* Icon */
.icon {
background: #260f03;
margin: 0 auto;
padding: 20px 20px 30px;
position: absolute;
width: 100%;
z-index: 500;
}
.icon div {
background: #d2b48c;
border-radius: 3px;
height: 2px;
margin: 10px auto 0;
position: relative;
transition: all 0.3s ease-in-out;
width: 3em;
}
/* Toggle */
#toggle:checked + .icon div:nth-child(1) {
margin-top: 25px;
transform: rotate(-45deg);
}
#toggle:checked + .icon div:nth-child(2) {
margin-top: -2px;
transform: rotate(45deg);
}
#toggle:checked + .icon div:nth-child(3) {
opacity: 0;
transform: rotate(45deg);
}
#toggle:checked + .icon + #nav {
top: 0;
transform: scale(1);
}
/* Nav */
#nav {
background: rgba(38, 15, 3, 0.95);
bottom: 0;
height: 100%;
left: 0;
overflow: hidden;
position: fixed;
right: 0;
top: -100%;
transform: scale(0);
transition: all 0.3s ease-in-out;
z-index: 200;
}
#nav div {
height: 100%;
overflow: hidden;
overflow-y: auto;
position: relative;
}
#nav ul {
padding-top: 90px;
text-align: center;
}
#nav li a:before {
background: #fff;
content: '';
height: 0;
left: -0.5em;
position: absolute;
transition: all 0.2s ease-in-out;
width: 0.25em;
}
#nav li a:hover:before {
height: 100%;
}
}
#media screen and (min-width: 601px) {
/* HIDE the dropdown */
#nav li ul { display: none; }
/* DISPLAY the dropdown */
#nav li:hover > ul {
display: block;
position: absolute;
}
/* Nav */
#nav ul {
background: #260f03;
font-size: 0;
text-align: center;
}
#nav li {
display: inline;
}
#nav li a:hover {
border-bottom: 1px solid #d2b48c;
border-top: 1px solid #d2b48c;
}
}
JS Fiddle (with submenus):https://jsfiddle.net/2v8zhL3e/1/
JS Fiddle (without submenus): https://jsfiddle.net/b0mj7gp4/
I've found a bunch of tutorials on how to do this, but they are all using a float on the li.
I did have a go at it...
I hid the dropdown: #nav li ul { display: none; }
Then I showed it on hover:
#nav li:hover > ul {
display: block;
position: absolute;
}
Which kind of works...but the links show to the left of the main navigation item, I'd like to just tweak this so the links are stacked and show centered under their corresponding header.
I feel like I'm close, can anyone point me in the right direction?
Thanks,
Josh
You can add display: flex to the li:hover ul, then make the flex-direction: column and make the non-hover event position: absolute, left: 0. This creates an issue with the ul child element floating to the far left. So to fix this issue, you need to style its parent to have a relative position. The following should do the trick.
#nav li {
position: relative;
}
#nav li ul {
left: 0;
position: absolute;
}
#nav li:hover > ul {
display: flex;
flex-direction: column;
}
You haven't position: relative in li.
And, it would be better to use position: absolute without hover, in default.
#nav li {
position: relative;
}
#nav li > ul {
position: absolute;
display: none;
}
#nav li:hover > ul {
display: block;
}
I am trying to animate slider up and down on toggle on navbar using javascript but the css transition property is not working on the ul element
Following is my updated codepen https://codepen.io/divya95/pen/vYNdKrz
Code:
<div class="container row">
<nav class="nav">
<a class="logo"><img src="../flexbox/vanderbilt-commodores-1.svg"></a>
<ul class="nav__list nav__list--primary">
<li class="nav__item">
Home
</li>
<li class="nav__item">
About
</li>
<li class="nav__item">
Contact Us
</li>
<li class="nav__item">
Sign In
</li>
<li class="nav__item">
Sign Up
</li>
</ul>
<button class="nav-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
<!-- <ul class="nav__list nav__list--secondary">
</ul> -->
</nav>
</div>
Css:
.nav-visible {
width: 100%;
text-align: center;
position: fixed;
display: flex;
flex-direction: column;
justify-content: center;
top: 40px;
display: block;
background: #2E323F;
list-style-type: none;
padding: 1em;
/* this is not working */
transition: height 5s ease;
}
Here I used jQuery because it's easier for me but you can make it without it.
notice how i also changed .nav-visible and .nav__list
$(document).ready(function(){
$('.nav-toggle').click(function () {
$(this).toggleClass('is-active');
toggleMenu($(this).hasClass('is-active'));
});
});
function toggleMenu(openMenu) {
let menu = $('.nav__list');
if(openMenu) {
menu.css('height', 'auto');
let nextHeight = menu.height();
menu.css('height', 0);
menu.animate({
'height': nextHeight,
'padding': '1em'
}, 200, function() {
menu.css({
'height': 'auto',
});
});
} else {
menu.css('overflow', 'hidden');
menu.animate({
'height': 0,
'padding': 0
}, 200);
}
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Montserrat', sans-serif;
font-size: 1.3125rem;
line-height: 1.6;
color: #222C2A;
}
.container {
max-width: 1200px;
}
.row {
display: flex;
justify-content: space-between;
}
.nav {
display: flex;
justify-content: space-between;
width: 100%;
background: #2E323F;
}
.nav__list {
height: 0;
overflow: hidden;
}
.nav__link {
text-decoration: none;
text-transform: uppercase;
font-size: 1rem;
font-weight: 600;
color: white;
}
.nav__list {
width: 100%;
text-align: center;
position: fixed;
display: flex;
flex-direction: column;
justify-content: center;
top: 40px;
display: block;
background: #2E323F;
list-style-type: none;
padding: 0em;
}
.nav-visible {
padding: 1em;
}
.nav-visible .nav__item {
padding-bottom: 1em;
}
.nav__link {
padding: 1em;
}
.logo {
margin-left: 2.5em;
}
.logo img {
width: 45px;
height: 45px;
margin-left: 1em;
margin-top: 0.5em;
margin-right: 0.5em;
}
.nav-toggle {
width: 2.5rem;
height: 2.5rem;
border-radius: 50%;
margin-top: 0.85em;
margin-right: 0.95em;
}
.bar {
cursor: pointer;
display: block;
height: 2px;
background: #222C2A;
transition: all 0.3s ease-in-out;
}
.bar:nth-child(1) {
-webkit-transform: translateY(-6px);
transform: translateY(-6px);
}
.bar:nth-child(3) {
-webkit-transform: translateY(6px);
transform: translateY(6px);
}
.hamburger-active .bar:nth-child(1) {
-webkit-transform: translateY(2px) rotate(45deg);
transform: translateY(2px) rotate(45deg);
}
.hamburger-active .bar:nth-child(2) {
opacity: 0;
}
.hamburger-active .bar:nth-child(3) {
-webkit-transform: translateY(-2px) rotate(-45deg);
transform: translateY(-2px) rotate(-45deg);
}
#media(min-width: 700px) {
header {
background: #2E323F;
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav {
display: flex;
justify-content: space-between;
}
.nav__list {
list-style-type: none;
display: flex;
/* visibility: visible; */
}
.nav__link {
text-decoration: none;
text-transform: uppercase;
font-size: 0.85rem;
margin-right: 0.8em;
}
.nav-toggle {
display: none;
}
.nav__item {
margin-right: 1.5em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
<div class="container row">
<nav class="nav">
<a class="logo"><img src="../flexbox/vanderbilt-commodores-1.svg"></a>
<ul class="nav__list nav__list--primary">
<li class="nav__item">
Home
</li>
<li class="nav__item">
About
</li>
<li class="nav__item">
Contact Us
</li>
<li class="nav__item">
Sign In
</li>
<li class="nav__item">
Sign Up
</li>
</ul>
<button class="nav-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
</nav>
</div>
</header>
I have hardcoded padding for each of the padding hierarchy level.
I need the solution for any of level without hardcoding padding for each level.
.jdm-nav li {
font-size: 16px;
position: relative;
}
.jdm-nav li a {
padding-left: 15px;
}
.jdm-nav li li a {
padding-left: 30px;
}
.jdm-nav li li li a {
padding-left: 45px;
}
.jdm-nav li li li li a {
padding-left: 60px;
}
li li li li ... a
Every next step could be increased by 15px.
Full code example.
There is the mobile menu with ability to dropdown each item by click dropdown icon in the right item corner. If there are the items to expand.
.jdm-nav {
background-color: white;
width: 100%;
padding: 0;
}
.jdm-nav ul {
padding: 0;
}
.jdm-nav {
list-style: none;
}
.jdm-nav li {
list-style: none;
}
.jdm-nav ul {
margin: 0;
}
.jdm-nav a {
text-align: left;
display: flex;
color: rgb(76, 92, 104);
font-weight: 500;
padding: .5em 0;
font-size: 16px;
border-bottom: 1px solid rgba(76, 92, 104, 0.1);
}
.jdm-nav li {
font-size: 16px;
position: relative !important;
}
.jdm-nav li a {
padding-left: 15px;
}
.jdm-nav li li a {
padding-left: 30px;
}
.jdm-nav li li li a {
padding-left: 45px;
}
.jdm-nav li li li li a {
padding-left: 60px;
}
.jdm-nav li {
position: relative;
}
.jdm-nav li>[data-jdm-sub-menu-switcher] {
font-size: 13px;
display: flex;
width: 100%;
height: 100%;
border-bottom: 1px solid rgba(76, 92, 104, 0.1);
position: relative;
}
.jdm-nav li {
position: relative !important;
}
.jdm-nav li.menu-item-has-children>ul {
max-height: 0;
overflow: hidden;
transition: 150ms max-height ease-out;
}
.jdm-nav li.menu-item-has-children>ul[data-jdm-state="expanded"] {
max-height: initial;
}
.jdm-nav li.menu-item-has-children> :first-child {
grid-column: 1;
}
.jdm-nav li.menu-item-has-children>[data-jdm-sub-menu-switcher] {
grid-column: 2;
}
.jdm-nav li.menu-item-has-children>ul {
grid-row: 2;
grid-column-start: 1;
grid-column-end: 3;
}
.jdm-nav li>[data-jdm-sub-menu-switcher]::after {
position: absolute;
}
.jdm-nav li>[data-jdm-sub-menu-switcher]::after {
position: absolute;
width: 1em;
height: 1em;
content: '';
clip-path: url(#prefix-mobile-dropdown-clip-mask);
font-size: 13px;
background-color: rgb(76, 92, 104);
display: inline-flex;
top: 50%;
right: 50%;
transform: translateY(-50%) translateX(50%);
}
.jdm-nav li.menu-item-has-children {
display: grid;
grid-template-columns: 100fr 15fr;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<div id="prefix-mobile-menu" class="mobile-menu-area prefix-mobile-menu" data-prefix-status="collapsed">
<nav id="mobile-menu" class="jdm-nav">
<ul id="primary-menu" class="menu-overflow">
<li id="menu-item-2420" class="menu-item-has-children">
1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu" style="" data-jdm-state="expanded">
<li id="menu-item-2418" class="menu-item-has-children">1.1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu" style="" data-jdm-state="expanded">
<li id="menu-item-2434" class="menu-item-has-children">1.1.1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu">
<li id="menu-item-2435">
1.1.1.1
</li>
<li id="menu-item-2436">1.1.1.2
</li>
<li id="menu-item-2437">1.1.1.3
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li id="menu-item-1832">2</li>
</ul>
</nav>
<svg width="0" height="0" viewBox="0 0 448 512">
<defs>
<clipPath
viewbox="0 0 448 512"
transform="scale(0.00223, 0.00195)"
clipPathUnits="objectBoundingBox"
id="prefix-mobile-dropdown-clip-mask">
<path fill="#000000"
d="M441.9 167.3l-19.8-19.8c-4.7-4.7-12.3-4.7-17 0L224 328.2 42.9 147.5c-4.7-4.7-12.3-4.7-17 0L6.1 167.3c-4.7 4.7-4.7 12.3 0 17l209.4 209.4c4.7 4.7 12.3 4.7 17 0l209.4-209.4c4.7-4.7 4.7-12.3 0-17z"
class=""></path>
</clipPath>
</defs>
</svg>
</div>
Put the padding on the li and stretch the left of the a out by a large fixed amount.
Illustrated:
body > ul {
border: 1px solid #eee;
border-radius: 2px;
margin: 1em;
padding: 1em;
overflow: hidden;
}
ul {
list-style: none;
padding: 0;
}
li {
padding-left: 15px;
}
a {
display: block;
margin-left: -150px;
margin-right: -1em;
padding-left: 150px;
}
a:hover {
background-color: #cff;
}
<ul>
<li>
nested
<ul>
<li>
navigation
<ul>
<li>
forever
<ul>
<li>
and
<ul>
<li>
ever
</ul>
</ul>
</ul>
<li>
foo
<li>
bar
</ul>
<li>
baz
</ul>
(Notice how the clickable area of each link extends all the way to the left.)
you can use this code for solve your problem
.jdm-nav li {
font-size: 16px;
position: relative;
}
.jdm-nav li{
font-size:1.2em;
padding-left: 3em;
}
.jdm-nav li a {
background-color:red;
font-size:16px;
}
<ul class="jdm-nav">
<li>
<a>Item1</a>
<ul>
<li>
<a>Item2</a>
<ul>
<li>
<a>Item3</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
use pseudo function of css to increase the padding of every children by 15px.
Right now the parent menu has an opacity shift on hover, this is being transferred to the sub menu (current & previous) as well. I want the sub menu to have a clear background so that the opacity band of the parent is the only thing that is visible. Is there a way to use an li class for the submenu that makes it exempt from the li class that is governing the parent. I've been trying different things but can't seem to make it work properly.
Demo
HTML
<div>
<ul id="mainmenu">
<li class="liHome">
<a class="maintextcolour" href="#item-x1y1" id="Home" rel=
"none">INFO</a>
</li>
<li class="liServices">
<a class="maintextcolour" href="#item-x1y2" id="Services" rel=
"SubMenuY2">EXHIBITIONS</a>
<ul class="submenu" id="SubMenuY2">
<li class="sub1">
<a class="maintextcolour" href="#">CURRENT</a>
</li>
<li class="sub1">
<a class="maintextcolour" href="#">PREVIOUS</a>
</li>
</ul>
</li>
<li id="liEnvironment">
<a class="maintextcolour" href="#item-x1y3" id="Environment"
rel="none">CV</a>
</li>
<li id="liCareer">
<a class="maintextcolour" href="#item-x1y4" id="Career" rel=
"none">NEWS</a>
</li>
<li id="liContact">
<a class="maintextcolour" href="#item-x1y5" id="Contact" rel=
"none">MORE</a>
</li>
</ul>
</div>
CSS:
#charset UTF-8;
/* CSS Document */
body {
background-color: #666;
background-size: 100%;
background-repeat: no-repeat;
}
#mainmenu {
margin: 0;
padding: 0;
list-style-type: none;
position: relative;
}
#mainmenu li {
clear: left;
position: relative;
}
#mainmenu a {
display: block;
overflow: hidden;
float: left;
width: 100%;
position: relative;
opacity: 1;
-webkit-transition: all .4s ease-in-out;
padding-left: 20px;
}
#mainmenu li:hover a {
background-position: 0 0;
background-color: clear;
background-color: rgba(255,255,255,0.5);
width: 100%;
opacity: 0;
-webkit-transition: none;
}
#mainmenu li.active a {
background-position: 0 0;
background-color: clear;
width: 100%;
}
.submenu {
list-style-type: none;
float: left;
display: none;
position: absolute;
left: 135px;
top: 0;
width: auto;
}
#mainmenu li a:hover + .submenu,.submenu:hover {
display: block;
}
.submenu li {
display: inline-block;
clear: none !important;
}
.submenu li a {
float: right;
margin-left: 10px;
}
.maintextcolour {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #FFF;
text-decoration: none;
}
.maintextcolour:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #0FF;
text-decoration: none;
}
.headertext {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFF;
text-decoration: none;
}
Here is the updated Fiddle link. I have just added color to the following css:
#mainmenu > li:hover > a {
background-position: 0 0;
background-color:clear;
color:#0fffff;
background-color:rgba(255,255,255,0.5);
width:100%;
\
opacity: 0;
-webkit-transition: none;
}
Hope you want this.