Custom menu with JS in WordPress theme - wordpress

I have my custom menu in HTML theme and I want to create same menu but in wordpress.
On my page u can see how it works...
In this menu I use jQuery and Bootstrap dropdown. How to create this menu using wp_nav_menu ?
This is my code (HTML, JS, CSS).
<script type="text/javascript">
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
(function($) {
$.fn.menumaker = function(options) {
var cssmenu = $(this), settings = $.extend({
title: "Menu",
format: "dropdown",
sticky: false
}, options);
return this.each(function() {
cssmenu.prepend('<div id="menu-button">' + settings.title + '</div>');
$(this).find("#menu-button").on('click', function(){
$(this).toggleClass('menu-opened');
var mainmenu = $(this).next('ul');
if (mainmenu.hasClass('open')) {
mainmenu.hide().removeClass('open');
}
else {
mainmenu.show().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').hide();
}
else {
$(this).siblings('ul').addClass('open').show();
}
});
};
if (settings.format === 'multitoggle') multiTg();
else cssmenu.addClass('dropdown');
if (settings.sticky === true) cssmenu.css('position', 'fixed');
resizeFix = function() {
if ($( window ).width() > 768) {
cssmenu.find('ul').show();
}
if ($(window).width() <= 768) {
cssmenu.find('ul').hide().removeClass('open');
}
};
resizeFix();
return $(window).on('resize', resizeFix);
});
};
})(jQuery);
(function($){
$(document).ready(function(){
$("#cssmenu").menumaker({
title: "Menu",
format: "multitoggle"
});
});
})(jQuery);
</script>
/*!
* Start Bootstrap - Simple Sidebar HTML Template (http://startbootstrap.com)
* Code licensed under the Apache License v2.0.
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
*/
/* Toggle Styles */
/* FB, wersja jezykowa */
.fb-language {
position: fixed;
bottom: 20px;
left: 65px;
list-style: none;
}
/* Ikonka jezyka */
.lang-item {
display: inline;
}
/* ikonka fb */
.fb-language img {
display: inline-block;
width: 20px;
height: auto;
}
.fb-language p {
display: inline-block;
color: #999999;
font-size: 12px;
margin-left: 5px;
}
.fb-language a {
text-decoration: none;
color: #999999;
}
.fb-language a:hover {
color: #656565;
text-decoration: underline;
}
/* Kolor linku w menu jezeli jestes na podstronie */
.current_page_item a {
color: black !important;
}
.page_item {
list-style: none !important;
}
.dropdown-toggle .icon-bar {
margin-bottom:4px;
margin-top: 4px;
display: block;
width: 22px;
height: 2px;
background-color: #ffffff;
border-radius: 1px;
}
/* kolor button'a dla mobilnego menu */
button {
background-color: rgb(230, 225, 225) !important;
text-align: left !important;
left: 8px !important;
position: absolute;
}
.navbar-header {
position: fixed !important;
width: 100% !important;
height: 45px !important;
background-color: rgb(255, 255, 255) !important;
border-radius: 0 !important;
margin: 0 auto !important;
text-align: center !important;
}
.navbar-header img {
width: 13% !important;
height: auto !important;
margin: 0 auto !important;
text-align: center !important;
}
#wrapper {
padding-top: 50px;
padding-left: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled {
padding-left: 250px;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
background-color: rgb(255, 255, 255);
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled #sidebar-wrapper {
width: 250px;
}
#page-content-wrapper {
width: 100%;
background-color: rgb(214, 214, 214);
position: absolute;
padding: 15px;
}
#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-right: -250px;
}
/* Sidebar Styles */
.sidebar-nav {
position: block;
top: 0;
width: 250px;
margin: 0;
padding-top: 9px;
padding-left: 50px;
list-style: none;
text-align: left;
}
.sidebar-nav li {
list-style: none;
text-indent: 20px;
line-height: 40px;
}
.sidebar-nav li a.bez:before {
content: " " !important;
}
.sidebar-nav li a {
display: block;
line-height: 18px;
text-decoration: none;
color: #999999;
}
.sidebar-nav li a:hover {
text-decoration: none;
color: #000;
}
.sidebar-nav li a:active,
.sidebar-nav li a:focus {
text-decoration: none;
}
.sidebar-nav > .sidebar-brand {
font-size: 14px;
line-height: 30px;
}
.sidebar-nav > .sidebar-brand a {
color: #999999;
}
.sidebar-nav > .sidebar-brand a:hover {
color: #000;
background: none;
}
.sidebar-nav > .sidebar-links {
padding-left: 43px;
}
.sidebar-nav2 {
position: block;
top: 0;
width: 250px;
margin: 0;
padding-top: 60px;
padding-left: 80px;
list-style: none;
text-align: left;
list-style: none;
text-transform: lowercase;
}
.sidebar-nav2 li {
text-indent: 20px;
line-height: 24px;
}
.sidebar-nav2 li a {
display: block;
text-decoration: none;
color: #999999;
}
.sidebar-nav2 li a:hover {
text-decoration: none;
color: #000;
}
.sidebar-nav2 li a:active,
.sidebar-nav2 li a:focus {
text-decoration: none;
}
#media(max-width: 769px) {
#wrapper {
padding-top: 70px !important;
}
.sidebar-nav {
padding-top: 5px !important;
margin-top: 0;
}
.fb-language {
position: absolute;
bottom: 20px;
left: 65px;
z-index: 10;
}
}
#media(min-width:769px) {
#wrapper {
padding-left: 250px;
}
#wrapper.toggled {
padding-left: 0;
}
#sidebar-wrapper {
width: 250px;
}
#wrapper.toggled #sidebar-wrapper {
width: 0;
}
#page-content-wrapper {
padding: 20px;
position: relative;
background-color: rgb(214, 214, 214);
}
#wrapper.toggled #page-content-wrapper {
position: relative;
margin-right: 0;
}
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- Sidebar -->
<div class="navbar-header navbar-toggle">
<button href="#menu-toggle" class="btn btn-xs btn-default dropdown-toggle" id="menu-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</a>
</div>
<div id="sidebar-wrapper">
<div class="sidebar-nav">
<li class="sidebar-brand"><span class="brand"></span> ARCHITEKTURA</li>
<ul class="collapse" id="arch">
<li>jednorodzinne</li>
<ul class="collapse" id="jedno">
<li>dom opolski</li>
<li>dom 2</li>
<li>dom 3</li>
</ul>
<li>wielorodzinne</li>
<ul class="collapse" id="wielo">
<li>dom 1</li>
<li>dom 2</li>
<li>dom 3</li>
</ul>
<li>usługowe</li>
<ul class="collapse" id="uslu">
<li>przedszkole w Chróścicach</li>
<li>obiekt 2</li>
<li>obiekt 3</li>
</ul>
</ul>
<li class="sidebar-brand">PORT DESIGN</li>
<ul class="collapse" id="design">
<li>meble</li>
<ul class="collapse" id="meble">
<li>stół 1</li>
<li>stół 2</li>
<li>krzesło 1</li>
</ul>
<li>ceramika</li>
<ul class="collapse" id="ceramika">
<li>ceramika 1</li>
<li>ceramika 2</li>
<li>ceramika 3</li>
</ul>
<li>grafika</li>
<ul class="collapse" id="grafika">
<li>grafika 1</li>
<li>grafika 2</li>
<li>grafika 3</li>
</ul>
<li>inne</li>
<ul class="collapse" id="inne">
<li>inne 1</li>
<li>inne 2</li>
<li>inne 3</li>
</ul>
</ul>
<li class="sidebar-brand">PORT MIEJSCE</li>
<ul class="collapse" id="miejsce">
<li>kawiarnia</li>
<ul class="collapse" id="kawiarnia">
<li>kawa</li>
<li>śniadanie</li>
<li>wydarzenia</li>
</ul>
<li>coworking</li>
<ul class="collapse" id="coworking">
<li>coworking 1</li>
<li>coworking 2</li>
<li>coworking 3</li>
</ul>
<li>warsztat</li>
<ul class="collapse" id="warsztat">
<li>warsztat 1</li>
<li>warsztat 2</li>
<li>warsztat 3</li>
</ul>
<li>cennik</li>
</ul>
</div>
</div>
</div>

I'm using the wordpress bootstrap navwalker for using the bootstrap menu. You can easily edit the walker.
Try https://github.com/twittem/wp-bootstrap-navwalker
~ Neme

In WordPress, the menus are usually done by using the admin dashboard UI. Using appearance -> Menus.
The drop-down ability is done by indenting sub-menu items to the parent menu item. Then it's either you add you own JavaScript to manipulate how the current menu behave, or your current theme could be doing it exactly how you want it.
I'd look into using the right theme as well.

Related

Adding Submenu to Existing Nav

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;
}

CSS Progress Stepper not working on first step

I followed a tutorial to make the following progress stepper. It won't show step 1 when it is set to active. The other steps work when they are set to active. Can someone please help me understand what needs to be changed in the CSS to allow step 1 to show as active?
I realize I could choose a different stepper, but I like this one because it's CSS only and I would like to learn from this issue.
.container {
width: 100%;
position: absolute;
z-index: 1;
}
.progressbar li {
float: left;
width: 20%;
position: relative;
text-align: center;
list-style: none;
}
.progressbar {
counter-reset: step;
}
.progressbar li:before {
content: counter(step);
counter-increment: step;
width: 30px;
height: 30px;
border: 2px solid #bebebe;
display: block;
margin: 0 auto 10px auto;
border-radius: 50%;
line-height: 27px;
background: white;
color: #bebebe;
text-align: center;
font-weight: bold;
}
.progressbar li:after {
content: '';
position: absolute;
width: 100%;
height: 3px;
background: #979797;
top: 15px;
left: -50%;
z-index: -1;
}
.progressbar li:first-child:after {
content: none;
}
.progressbar li.active+li:after {
background: #3aac5d;
}
.progressbar li.active+li:before {
border-color: #3aac5d;
background: #3aac5d;
color: white
}
<div class="container">
<ul class="progressbar">
<li class="active">Step 1</li>
<li>Step 2</li>
<li>Step 3</li>
<li>Step 4</li>
<li>Step 5</li>
</ul>
</div>
If you add the active class to each <li> after it's done, then simply removing the +li from your selectors seems to work:
Fiddle: https://jsfiddle.net/fwpadbty/

How to sequentually increase CSS value for Padding property for Hierarchy structure?

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.

fixing margin and padding on navigtion bar dropdown

currently when you hover over the drop down you will see the drop down links. in the drop down menu to the left of the links there is a gap. I would like that gap removed.
this is for my navigation bar drop down in desktop mode only.
this for my website JGittech.com.
it needs me to type more
all help would be appreciated
/*! CSS Used from: https://jgittech.com/stylesheets/nav.v5.css */
* {
box-sizing: border-box;
font-family: Arial,Helvetica,sans-serif
}
.menu-item-has-children .menu-li .nav-ul-li-a:hover,.sub-menu .menu-li .nav-ul-li-a:hover,.sub-menu .menu-li:hover {
background: #006084;
color: #fff
}
.navcontainer {
z-index: 999;
position: fixed;
top: 0;
left: 0;
margin: auto;
width: 100%
}
.active {
background: #009fd8;
color: #fff
}
.main-navigation {
background: #333
}
.nav-ul,body {
list-style-type: none;
padding: 0;
margin: 0
}
.fixednav,.menu {
display: flex
}
.menu {
flex-direction: column
}
.menu-li {
display: block;
list-style-type: none
}
.menu .nav-ul-li-a {
display: block;
text-align: center;
text-decoration: none;
color: #fff;
padding: 20px 1rem
}
.menu-li .nav-ul-li-a:hover,a:hover {
color: #fff
}
.nav-ul-ul {
display: none
}
.nav-ul .menu-li:hover>ul {
max-width: 100%;
display: block;
color: #fff
}
.fixednav {
flex-direction: row;
z-index: 9999;
width: 100%;
height: 60px
}
.leftnav {
line-height: 20px
}
#media (min-width:800px) {
.menu {
display: flex;
flex-direction: row;
justify-content: flex-start
}
.nav-ul .menu-li:hover>ul {
background: #333
}
.nav-ul .menu-li:hover>.nav-ul-li-a,.sub-menu .menu-li .nav-ul-li-a:hover,.sub-menu .menu-li:hover {
background: #006084;
color: #fff
}
.sub-menu .menu-li {
display: flex;
padding-right: 1em
}
.nav-ul-ul {
position: absolute
}
.nav-ul-ul,input[data-function*=swipe],label[data-function*=swipe] {
display: none
}
}
#media (max-width:799px) {
.nav-ul .menu-li:hover>ul {
background: #263249
}
.nav-ul .menu-li:hover>.nav-ul-li-a {
color: #fff
}
.menu-item-has-children .menu-li .nav-ul-li-a:hover,.sub-menu .menu-li .nav-ul-li-a:hover,.sub-menu .menu-li:hover {
background: #006084;
color: #fff
}
.fixednav,.nav-ul-ul {
display: block
}
label[data-function*=swipe] {
display: block;
position: absolute;
top: 30px;
left: 30px;
z-index: 1;
width: 42px;
height: 42px;
font: 42px fontawesome;
text-align: center;
color: #333;
cursor: pointer;
transform: translate3d(0,0,0);
transition: transform .3s
}
.fixednav {
text-align: left
}
.menu .nav-ul-li-a {
display: block;
text-decoration: none;
padding: 0 20px;
color: #fff;
border: 3px solid #fff;
text-align: center;
font-size: 18px;
font-weight: 900;
padding: 20px 1rem;
margin: 0 20px
}
.nav1contain {
display: flex;
height: 60px
}
input[data-function*=swipe] {
position: absolute;
opacity: 0
}
label[data-function*=swipe]:hover {
color: #263249
}
input[data-function*=swipe]:checked~label[data-function*=swipe] {
transform: translate3d(280px,0,0)
}
label[data-function*=swipe]:checked {
display: block
}
label:nth-child(2) {
display: none
}
input[data-function*=swipe]:checked~label:nth-child(2) {
display: block;
transform: translate3d(280px,0,0)
}
input[data-function*=swipe]:checked~label:nth-child(3) {
display: none
}
input[data-function*=swipe]:checked~.sidebar {
transform: translate3d(0,0,0)
}
input[data-function*=swipe]:checked~.sidebar .menu-li {
width: 100%
}
.sidebar {
transform: translate3d(-280px,0,0);
position: absolute;
width: 280px;
background: #263249;
color: #eee;
left: 0;
transition: all .3s
}
.menu-li {
display: inline-block;
padding: 10px;
list-style: none;
background: #263249;
list-style-type: none
}
.menu-item-has-children:hover {
display: block
}
}
.button {
display: block;
width: calc(100% - 30px);
height: 40px;
margin: 2% 15px;
background-color: #009fd8;
box-shadow: 0 6px 9px rgba(50,50,93,.06),0 2px 5px rgba(0,0,0,.08),inset 0 1px 0 #ffb9f6;
border-radius: 4px;
color: #fff;
font-weight: 600;
cursor: pointer
}
.active2 {
background: #00569b;
color: #fff
}
<div class="nav1contain">
<input data-function="swipe" id="swipe" type="checkbox">
<label data-function="swipe" for="swipe"></label>
<label data-function="swipe" for="swipe"></label>
<div class="navcontainer sidebar">
<nav class="main-navigation fixednav menu">
<ul class="menu nav-ul">
<li class = "menu-li"><a class = " active leftnav nav-ul-li-a" href="../index.html">Home</a></li>
<li class = "menu-li"> <a class = "nav-ul-li-a " href="pages/about.html">About</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/products.html">Products</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/contact.html">Contact</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="https://statuspage.freshping.io/13300-JGittechLLCStatusPage/check/91333">Status</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="../sitemap.html">Sitemap</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/video.html">Videos</a> </li>
<li class="menu-item-has-children menu-li"> <a class ="nav-ul-li-a" href="#">Legal +</a>
<ul class="nav-ul-ul">
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/legal/terms.pdf">Terms of Use</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/legal/privacy.pdf">Privacy Policy</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/legal/disclaimer.pdf">Disclaimer Policy</a> </li>
<li class = "menu-li"><a class = "nav-ul-li-a" href="pages/legal/cookie.html">Cookie Policy</a> </li>
<li class = "menu-li"> <a class = "nav-ul-li-a" href="pages/legal/return.pdf">Return Policy</a> </li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
.
.nav-ul-ul { padding:0; } should do the trick.

Opacity on hover of parent is being transfered to submenu; how to prevent this using CSS

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.

Resources