I have one page scroll menu,but i've changed that in multiple page.These kind of menu is working on desktop,but is not working on mobile version.How can I change code css or html because in mobile version when i click on menu and close it anywhere i clicked redirectg me to another page.
.mobile-menu {
display: block;
width: 18%;
right: -20%;
height: 100%;
background: rgba(1, 16, 25, 0.67);
position: fixed;
z-index: 9998;
transition: 0.6s ease;
top: 0;
opacity: 0;
}
.mobile-menu ul {
position: relative;
top: 20%;
padding: 0;
}
.mobile-menu ul li {
list-style: none;
margin-bottom: 2em;
display: block;
}
.mobile-menu ul li a {
width: 100%;
margin: 0 auto;
display: block;
text-align: center;
text-decoration: none;
color: #fff;
font-size: 1em;
font-weight: bold;
overflow: hidden;
position: relative;
padding: 1em 0;
text-transform: uppercase;
letter-spacing: 3px;
}
.open > ul.dropdown-menu.agile_short_dropdown{
display: block;
transform: none !important;
min-width: 65%;
border: none;
box-shadow: none;
border-radius: 0;
left: 18%;
}
.open > ul.dropdown-menu.agile_short_dropdown li{
margin:0 !important;
}
ul.dropdown-menu.agile_short_dropdown > li > a:hover{
background: none;
}
.mobile-menu ul li a:after {
content: '';
background: #191143;
width: 100%;
height: 100%;
position: absolute;
right: -100%;
top: 0;
z-index: -1;
transition: 0.4s ease;
}
.mobile-menu ul li a:hover,.mobile-menu ul li.active a {
color: #fff;
}
.mobile-menu ul li a:hover:after,.mobile-menu ul li.active a:after {
right: 0;
}
li.dropdown.act a.w3_icons_act {
background: #0e0e0e;
color: #fff;
}
.mobile-menu img {
position: absolute;
width: 150px;
display: block;
left: 50%;
top: 3rem;
transform: translatex(-50%);
-webkit-transform: translatex(-50%);
-moz-transform: translatex(-50%);
-o-transform: translatex(-50%);
-ms-transform: translatex(-50%);
padding: 0;
text-align: center;
}
.mobile-menu--open {
opacity: 1;
right:0%;
}
.dropdown.active.open a ul.dropdown-menu.agile_short_dropdown li a.w3_icon_1:after{
background:none !important;
<div class="center-container">
<div class="w3_agile_header">
<div class="w3_menu">
<div class="agileits_w3layouts_banner_info">
</div>
<div class="mobile-nav-button">
<div class="mobile-nav-button__line"></div>
<div class="mobile-nav-button__line"></div>
<div class="mobile-nav-button__line"></div>
</div>
<nav class="mobile-menu">
<ul>
<li><a href="https://ioanasandu.ro/online/web/index.html" class="hover" >Despre mine</a></li>
<li>Repertoriu</li>
<li>Discografie</li>
<li>Evenimente</li>
<li>Foto</li>
<li>Video</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="clearfix"></div>
</div>
Can anyone help me?
Related
im trying to replicate the "Page" Dropdown Animation with the icon, but im having difficulties, someone know how to make it similar to the "Page scroll one"?
Im leaving the code, you can find the Button than im trying to replicate with the icon dropdown and where i am at the moment.
Here is the HTML CODE:
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css2?family=Play:wght#400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght#300;400;500;600;700&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<header class="header">
<div class="container">
<div class="row">
<div class="col-lg-2">
<div class="header__logo">
<img src="img/logo.png" alt="">
</div>
</div>
<div class="col-lg-10">
<div class="header__nav__option">
<nav class="header__nav__menu mobile-menu">
<ul>
<li>Pages
<ul class="dropdown">
<li>About</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Blog Details</li>
</ul>
</li>
</ul>
</nav>
<div class="header__nav__settings">
<ul>
<a href="#"><i class="fa fa-gear"></i>
<ul class="dropdown">
<li>Portfolio</li>
<li>Blog</li>
<li>Blog Details</li>
</ul>
</a>
</ul>
</div>
</div>
</div>
</div>
<div id="mobile-menu-wrap"></div>
</div>
</header>
Here is the css
.header {
position: absolute;
left: 0;
top: 0;
width: 100%;
background: transparent;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
z-index: 9;
}
.header__nav__menu {
display: inline-block;
margin-right: 45px;
}
.header__nav__menu ul li {
list-style: none;
display: inline-block;
margin-right: 45px;
position: relative;
}
.header__nav__menu ul li.active a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__menu ul li:hover a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__menu ul li:hover .dropdown {
top: 34px;
opacity: 1;
visibility: visible;
}
.header__nav__menu ul li:last-child {
margin-right: 0;
}
.header__nav__menu ul li .dropdown {
position: absolute;
left: 0;
top: 60px;
width: 140px;
background: black;
text-align: left;
padding: 2px 0;
z-index: 9;
opacity: 0;
visibility: hidden;
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
.header__nav__menu ul li .dropdown li {
display: block;
margin-right: 0;
}
.header__nav__menu ul li .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__menu ul li .dropdown li a:after {
display: none;
}
.header__nav__menu ul li a {
font-size: 15px;
font-family: "Play", sans-serif;
color: black;
display: block;
text-transform: uppercase;
position: relative;
padding: 6px 0;
}
.header__nav__menu ul li a:after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background: #00bfe7;
content: "";
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
/*Settings Dropdown*/
.header__nav__settings {
display: inline-block;
position: relative;
padding-left: 50px;
}
.header__nav__settings:before {
position: absolute;
left: 0;
top: 4px;
height: 13px;
width: 2px;
background: rgba(225, 225, 225, 0.2);
content: "";
}
.header__nav__settings a {
color: black;
font-size: 15px;
}
.header__nav__settings a:last-child {
margin-right: 0;
}
.slicknav_menu {
display: none;
}
/*Settings Dropdown Content*/
.header__nav__settings ul a {
list-style: none;
display: inline-block;
margin-right: 45px;
position: relative;
}
.header__nav__settings ul a i.active a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__settings ul a i:hover a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__settings ul:hover .dropdown {
top: 34px;
opacity: 1;
visibility: visible;
}
.header__nav__settings ul .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__settings ul .dropdown {
position: absolute;
left: 0;
top: 60px;
width: 140px;
background: black;
text-align: left;
padding: 2px 0;
z-index: 9;
opacity: 0;
visibility: hidden;
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
.header__nav__settings ul .dropdown li {
display: block;
margin-right: 0;
}
.header__nav__settings ul li .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__settings ul a .dropdown li a:after {
display: none;
}
.header__nav__settings ul li a {
font-size: 15px;
font-family: "Play", sans-serif;
color: black;
display: block;
text-transform: uppercase;
position: relative;
padding: 6px 0;
}
.header__nav__settings ul li a:after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background: #00bfe7;
content: "";
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
Thank u in adavnce for the help!!!
Your code is wrong because your wrote <i> instead of <li> and you didn't close the <a> where you should. This is the code corrected:
.header {
position: absolute;
left: 0;
top: 0;
width: 100%;
background: transparent;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
z-index: 9;
}
.header__nav__menu {
display: inline-block;
margin-right: 45px;
}
.header__nav__menu ul li {
list-style: none;
display: inline-block;
margin-right: 45px;
position: relative;
}
.header__nav__menu ul li.active a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__menu ul li:hover a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__menu ul li:hover .dropdown {
top: 34px;
opacity: 1;
visibility: visible;
}
.header__nav__menu ul li:last-child {
margin-right: 0;
}
.header__nav__menu ul li .dropdown {
position: absolute;
left: 0;
top: 60px;
width: 140px;
background: black;
text-align: left;
padding: 2px 0;
z-index: 9;
opacity: 0;
visibility: hidden;
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
.header__nav__menu ul li .dropdown li {
display: block;
margin-right: 0;
}
.header__nav__menu ul li .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__menu ul li .dropdown li a:after {
display: none;
}
.header__nav__menu ul li a {
font-size: 15px;
font-family: "Play", sans-serif;
color: black;
display: block;
text-transform: uppercase;
position: relative;
padding: 6px 0;
}
.header__nav__menu ul li a:after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background: #00bfe7;
content: "";
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
/*Settings Dropdown*/
.header__nav__settings {
display: inline-block;
position: relative;
padding-left: 50px;
}
.header__nav__settings:before {
position: absolute;
left: 0;
top: 4px;
height: 13px;
width: 2px;
background: rgba(225, 225, 225, 0.2);
content: "";
}
.header__nav__settings a {
color: black;
font-size: 15px;
}
.header__nav__settings a:last-child {
margin-right: 0;
}
.slicknav_menu {
display: none;
}
/*Settings Dropdown Content*/
.header__nav__settings ul a {
list-style: none;
display: inline-block;
margin-right: 45px;
position: relative;
}
.header__nav__settings ul a i.active a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__settings ul a i:hover a:after {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.header__nav__settings ul:hover .dropdown {
top: 34px;
opacity: 1;
visibility: visible;
}
.header__nav__settings ul .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__settings ul .dropdown {
position: absolute;
left: 0;
top: 60px;
width: 140px;
background: black;
text-align: left;
padding: 2px 0;
z-index: 9;
opacity: 0;
visibility: hidden;
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
.header__nav__settings ul .dropdown li {
display: block;
margin-right: 0;
}
.header__nav__settings ul li .dropdown li a {
font-size: 14px;
color: white;
padding: 8px 20px;
text-transform: capitalize;
}
.header__nav__settings ul a .dropdown li a:after {
display: none;
}
.header__nav__settings ul li a {
font-size: 15px;
font-family: "Play", sans-serif;
color: black;
display: block;
text-transform: uppercase;
position: relative;
padding: 6px 0;
}
.header__nav__settings ul li a:after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background: #00bfe7;
content: "";
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
-webkit-transition: all, 0.3s;
-o-transition: all, 0.3s;
transition: all, 0.3s;
}
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css2?family=Play:wght#400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght#300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<header class="header">
<div class="container">
<div class="row">
<div class="col-lg-2">
<div class="header__logo">
<img src="img/logo.png" alt="">
</div>
</div>
<div class="col-lg-10">
<div class="header__nav__option">
<nav class="header__nav__menu mobile-menu">
<ul>
<li>Pages
<ul class="dropdown">
<li>About</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Blog Details</li>
</ul>
</li>
</ul>
</nav>
<div class="header__nav__settings">
<ul>
<li class="fa fa-gear">
<ul class="dropdown">
<li>Portfolio</li>
<li>Blog</li>
<li>Blog Details</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<div id="mobile-menu-wrap"></div>
</div>
</header>
nav {
display: inline-flex;
align-items: center;
width: 100%;
height: 8rem;
border-bottom: 1px solid black;
}
.nav-list {
display: flex;
width: 100%;
}
.nav-list li {
line-height: 8rem;
position: relative;
}
.sub-menu li {
color: #c40707;
line-height: 7rem;
}
.nav-list a {
display: block;
color: black;
padding: 0 1.5rem;
font-size: 1.4rem;
text-transform: uppercase;
transition: color 300ms;
}
.nav-list a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 3px;
width: 0;
left: 0;
bottom: 15px;
transition: 0s;
}
.nav-list a:hover::after {
width: 100%;
}
.nav-list a:hover {
color: #e3dedd;
}
.sub-menu a {
color: #7e7978;
font-size: 1.5rem;
font-weight: 200;
}
.sub-menu {
width: 20rem;
display: block;
position: absolute;
visibility: hidden;
z-index: 500;
background-color: rgb(255, 255, 255);
box-sizing: border-box;
top: 2rem;
}
.nav-list li:hover>.sub-menu {
top: 7.5rem;
opacity: 1;
visibility: visible;
}
<header>
<ul class="nav-list">
<li>
Men
<ul class="sub-menu">
<li>shirts</li>
<li>Shorts</li>
<li>Tracks</li>
<li>Shoes</li>
</ul>
</li>
</ul>
</header>
Im trying to create a dropdown using CSS. I created a nav bar with certain elements that are mentioned in the code. I applied a hover effect to the nav bar. I created a dropdown using .nav-list li: hover > .sub-menu as the command. However, the hover effect I had for the nav bar is being applied to the sub menu too. How to prevent this from happening?
The problem is that you need to be more specific in your CSS selectors. Since you only want the hover to affect the "Men" top level parent element, you need to use the direct descendent > selector after your .nav-list selector - since you only want the top level li a.
I changed your CSS in this part:
.nav-list > li > a {
display: block;
color: black;
padding: 0 1.5rem;
font-size: 1.4rem;
text-transform: uppercase;
transition: color 300ms;
}
.nav-list > li > a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 3px;
width: 0;
left: 0;
bottom: 15px;
transition: 0s;
}
.nav-list > li > a:hover::after {
width: 100%;
}
That ensures that only the top level direct children elements li and a are selected.
nav {
display: inline-flex;
align-items: center;
width: 100%;
height: 8rem;
border-bottom: 1px solid black;
}
.nav-list {
display: flex;
width: 100%;
}
.nav-list li {
line-height: 8rem;
position: relative;
}
.sub-menu li {
color: #c40707;
line-height: 7rem;
}
.nav-list > li > a {
display: block;
color: black;
padding: 0 1.5rem;
font-size: 1.4rem;
text-transform: uppercase;
transition: color 300ms;
}
.nav-list > li > a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 3px;
width: 0;
left: 0;
bottom: 15px;
transition: 0s;
}
.nav-list > li > a:hover::after {
width: 100%;
}
.nav-list a:hover {
color: #e3dedd;
}
.sub-menu a {
color: #7e7978;
font-size: 1.5rem;
font-weight: 200;
}
.sub-menu {
width: 20rem;
display: block;
position: absolute;
visibility: hidden;
z-index: 500;
background-color: rgb(255, 255, 255);
box-sizing: border-box;
top: 2rem;
}
.nav-list li:hover > .sub-menu {
top: 7.5rem;
opacity: 1;
visibility: visible;
}
<header>
<ul class="nav-list">
<li>
Men
<ul class="sub-menu">
<li>shirts</li>
<li>Shorts</li>
<li>Tracks</li>
<li>Shoes</li>
</ul>
</li>
</ul>
</header>
Add the class "main-menu-item"
<a class="main-menu-item" href="%">Men</a>
In the CSS Code, change your hover and after effect from "a" to this:
.nav-list .main-menu-item::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 3px;
width: 0;
left: 0;
bottom: 15px;
transition: 0s;
}
.nav-list .main-menu-item:hover {
color: #e3dedd;
}
Here is the running example:
nav {
display: inline-flex;
align-items: center;
width: 100%;
height: 8rem;
border-bottom: 1px solid black;
}
.nav-list {
display: flex;
width: 100%;
}
.nav-list li {
line-height: 8rem;
position: relative;
}
.sub-menu li {
color: #c40707;
line-height: 7rem;
}
.nav-list a {
display: block;
color: black;
padding: 0 1.5rem;
font-size: 1.4rem;
text-transform: uppercase;
transition: color 300ms;
}
.nav-list .main-menu-item::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 3px;
width: 0;
left: 0;
bottom: 15px;
transition: 0s;
}
.nav-list a:hover::after {
width: 100%;
}
.nav-list .main-menu-item:hover {
color: #e3dedd;
}
.sub-menu a {
color: #7e7978;
font-size: 1.5rem;
font-weight: 200;
}
.sub-menu {
width: 20rem;
display: block;
position: absolute;
visibility: hidden;
z-index: 500;
background-color: rgb(255, 255, 255);
box-sizing: border-box;
top: 2rem;
}
.nav-list li:hover>.sub-menu {
top: 7.5rem;
opacity: 1;
visibility: visible;
}
<header>
<div class="container">
<nav>
</div>
<ul class="nav-list">
<li>
<a class="main-menu-item" href="%">Men</a>
<ul class="sub-menu">
<li>
shirts
</li>
<li>
Shorts
</li>
<li>
Tracks
</li>
<li>
Shoes
</li>
</ul>
</li>
</ul>
</header>
I have this navbar setup on my page, I would like for it to work as normal on a tablet or desktop and then when loaded on a mobile device for the navbar to be condesnsed into a pressable hamburger menu.
What would be the best way to tackle this?
HTML and CSS Code are as follows
HTML
<h1 class='logo'><a href='#'>Website Logo</a></h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Portfolio</li>
</ul>
</nav>
</header>
CSS
header{
display: flex;
justify-content: space-around;
width: 100%;
background: #616880;
height: 70px;
}
.sticky {
position: fixed;
top:0;
width: 100%;
}
.logo{
margin: 15px 0 0 0;
}
nav {
margin: 25px;
}
ul li{
list-style: none;
display: inline;
}
ul li a,
h1 a{
text-decoration: none;
color: #fff;
padding: 5px;
}
Solution 1 Using pure CSS
body {
margin: 0;
font-family: Helvetica, sans-serif;
background-color: #f4f4f4;
}
a {
color: #000;
}
/* header */
.header {
background-color: #fff;
box-shadow: 1px 1px 4px 0 rgba(0,0,0,.1);
position: fixed;
width: 100%;
z-index: 3;
}
.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
}
.header li a {
display: block;
padding: 20px 20px;
border-right: 1px solid #f4f4f4;
text-decoration: none;
}
.header li a:hover,
.header .menu-btn:hover {
background-color: #f4f4f4;
}
.header .logo {
display: block;
float: left;
font-size: 2em;
padding: 10px 20px;
text-decoration: none;
}
/* menu */
.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
}
/* menu icon */
.header .menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 28px 20px;
position: relative;
user-select: none;
}
.header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}
.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.header .menu-icon .navicon:before {
top: 5px;
}
.header .menu-icon .navicon:after {
top: -5px;
}
/* menu btn */
.header .menu-btn {
display: none;
}
.header .menu-btn:checked ~ .menu {
max-height: 240px;
}
.header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
/* 48em = 768px */
#media (min-width: 48em) {
.header li {
float: left;
}
.header li a {
padding: 20px 30px;
}
.header .menu {
clear: none;
float: right;
max-height: none;
}
.header .menu-icon {
display: none;
}
}
<header class="header">
Your Logo
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Portfolio</li>
</ul>
</header>
Solution 2 Using JS and CSS
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
#charset "UTF-8";
body{
margin:0;
}
.navigation {
height: 70px;
background: #6d7993;
font-family: montserrat, sans-serif;
font-weight: 400;
font-style: normal;
opacity: 0.88;
}
.brand {
position: absolute;
padding-left: 20px;
float: left;
line-height: 70px;
text-transform: uppercase;
font-size: 1.4em;
}
.brand a,
.brand a:visited {
color: #ffffff;
text-decoration: none;
}
.nav-container {
max-width: 1000px;
margin: 0 auto;
}
nav {
float: right;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a,
nav ul li a:visited {
display: block;
padding: 0 20px;
line-height: 70px;
background: #6d7993;
color: #ffffff;
text-decoration: none;
}
nav ul li a:hover,
nav ul li a:visited:hover {
background: #4b5569;
color: #ffffff;
}
nav ul li a:not(:only-child):after,
nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: " ▾";
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: #6d7993;
height: 70px;
width: 70px;
}
#media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 70px 0 15px;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
#media screen and (min-width: 799px) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span,
#nav-toggle span:before,
#nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #ffffff;
position: absolute;
display: block;
content: "";
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
article {
max-width: 1000px;
margin: 0 auto;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<section class="navigation">
<div class="nav-container">
<div class="brand">
Eric Samson
</div>
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
GIS Projects
</li>
<li>
R Studio
</li>
<li>
Contact
</li>
</ul>
</ul>
</nav>
</div>
</section>
NOTE: View Snippet in full screen
You can use javascript. For better understanding, you can look at this link: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_topnav Also you can use jquery too.
I've a module which renders html menu markup. This markup can't be overridden.
So in order to make the menu look like it should I have to write some custom CSS code.
The problem is that on hover the submenu doesn't show up underneath its parent.
html:
<div class="moduletable_menu slider-menu">
<ul class="menu">
<li class="item-122 default current active">Products From Metal</li>
<li class="item-126 menu-deeper menu-parent">
Products<span class="menu-toggler"></span>
<ul class="menu-child">
<li class="item-123">Sliding Fence</li>
</ul>
</li>
</ul>
</div>
CSS:
.slider-menu {
display: block;
}
.slider-menu ul {
list-style: none;
padding: 0;
margin: 0 -15px;
z-index: 99;
display: block;
float: right;
position: relative;
}
.slider-menu ul li {
display: inline-block;
position: relative;
padding: 0;
}
.slider-menu ul li a {
display: inline-block;
padding: 0 15px;
line-height: 60px;
font-size: 14px;
margin: 0;
color:#fff;
}
.slider-menu .menu-deeper.menu-parent{
display: inline-block;
position: relative;
padding: 0;
list-style: none;
}
.slider-menu .menu-deeper.menu-parent li a{
display: inline-block;
padding: 0 15px;
line-height: 60px;
font-size: 14px;
margin: 0;
}
.slider-menu > ul li.menu-deeper > a::after {
font-family: "FontAwesome";
content: "\f107";
float: right;
margin-left: 7px;
}
.slider-menu .menu-child {
display: none;
}
.slider-menu .menu-child li {
display: block;
padding: 0;
position: relative;
}
.slider-menu .menu-child li > a {
font-size: 14px;
line-height: 1;
display: inline-block;
padding: 8px 0;
cursor: pointer;
}
.slider-menu .menu-deeper.menu-parent:hover > .menu-child {
animation: spFadeInUp 400ms ease-in;
display: block;
}
.slider-menu ul li a:hover {
color: red;
}
JSFiddle
So, I've missed something... Need proper corrections.
Adding position: absolute; top: 100%; to the child menu will position the menu absolutely directly below the parent li with position: relative;
.slider-menu .menu-child {
display: none;
position: absolute;
top: 100%;
}
body{
background-color:black;
}
.slider-menu {
display: block;
position:absolute;/*just to position it to the left corner in the JSFiddle example*/
top:0;
}
.slider-menu > ul {
float: right;
}
.slider-menu ul {
list-style: none;
padding: 0;
margin: 0 -15px;
z-index: 99;
display: block;
position: relative;
}
.slider-menu ul li {
display: inline-block;
position: relative;
padding: 0;
}
.slider-menu ul li a {
display: inline-block;
padding: 0 15px;
line-height: 60px;
font-size: 14px;
margin: 0;
color:#fff;
}
.slider-menu .menu-deeper.menu-parent{
display: inline-block;
position: relative;
padding: 0;
list-style: none;
}
.slider-menu .menu-deeper.menu-parent li a{
display: inline-block;
padding: 0 15px;
line-height: 60px;
font-size: 14px;
margin: 0;
}
.slider-menu > ul li.menu-deeper > a::after {
font-family: "FontAwesome";
content: "\f107";
float: right;
margin-left: 7px;
}
.slider-menu .menu-child {
display: none;
}
.slider-menu .menu-child li {
display: block;
padding: 0;
position: relative;
}
.slider-menu .menu-child li > a {
font-size: 14px;
line-height: 1;
display: inline-block;
padding: 8px 0;
cursor: pointer;
}
.slider-menu .menu-deeper.menu-parent:hover > .menu-child {
animation: spFadeInUp 400ms ease-in;
display: block;
position: absolute;
top: 100%;
}
.slider-menu ul li a:hover {
color: red;
}
#keyframes spFadeInUp {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
<div class="moduletable_menu slider-menu">
<ul class="menu">
<li class="item-122 default current active">Products From Metal</li>
<li class="item-126 menu-deeper menu-parent">
Products<span class="menu-toggler"></span>
<ul class="menu-child">
<li class="item-123">Sliding Fence</li>
</ul>
</li>
</ul>
</div>
Update
To match the parent text horizontally you can match the padding of 15px that the parent <li> has
.slider-menu .menu-child {
display: none;
position: absolute;
top: 100%
padding: 0 15px;
}
My Homepage-Menu-Point "Software" should stay opened if you click on it!
See on my Test-Homepage!
I've tested to add "li:focus" and "li:active" to my lowermost CSS-Tag, but nothing worked. I also tried it with jQuery, without success!
The HTML-Code:
<nav id="cNav">
<div class="Nav">
<ul>
<li>G</li>
<li>Home</li>
<li>Software
<ul>
<li>Android</li>
<li>Windows</li>
</ul>
</li>
<li>Über</li>
</ul>
</div>
</nav>
The CSS-Code:
#cNav {
background-color: rgb(5, 90, 160);
margin: 0;
padding: 0;
width: 100%;
}
.Nav {
font-weight: bold;
font-size: 22pt;
margin: 0;
padding: 0;
}
.Nav ul {
padding: 0;
margin-top: 0;
margin-bottom: 0;
position: relative;
width: 100%;
text-align: center;
}
.Nav ul li {
display: inline-block;
position: relative;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.4em;
padding-bottom: 0.4em;
}
.Nav ul li a {
outline: 0;
color: white;
position: relative;
text-decoration: none;
transition: color 0.3s;
}
.Nav ul li a::after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 4px;
background: white;
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
transform: translateY(10px);
margin: 0;
}
.Nav ul li a:hover::after {
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.Nav ul ul {
display: none;
white-space: nowrap;
position: absolute;
text-align: center;
top: 100%;
margin-left: -5.3em;
}
.Nav ul ul li {
background-color: rgb(5, 90, 160);
border-top: medium solid rgba(0,115,209,1.00);
margin-right: -1em;
}
.Nav ul li:hover > ul {
display: block;
}
If you want your Homepage-Menu-Point "Software" staying opened if you click on it, and you want to use jQuery, this might be a possible solution:
Add an id to the li with software:
<li id="software">Software
Then you can use this to set the css display property of the ul to block:
$(document).ready(function() {
$("#software ul").click(function() {
$(this).css("display", "block");
});
});
Snippet:
$(document).ready(function() {
$("#software ul").click(function() {
$(this).css("display", "block");
});
});
#cNav {
background-color: rgb(5, 90, 160);
margin: 0;
padding: 0;
width: 100%;
}
.Nav {
font-weight: bold;
font-size: 22pt;
margin: 0;
padding: 0;
}
.Nav ul {
padding: 0;
margin-top: 0;
margin-bottom: 0;
position: relative;
width: 100%;
text-align: center;
}
.Nav ul li {
display: inline-block;
position: relative;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.4em;
padding-bottom: 0.4em;
}
.Nav ul li a {
outline: 0;
color: white;
position: relative;
text-decoration: none;
transition: color 0.3s;
}
.Nav ul li a::after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 4px;
background: white;
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
transform: translateY(10px);
margin: 0;
}
.Nav ul li a:hover::after {
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.Nav ul ul {
display: none;
white-space: nowrap;
position: absolute;
text-align: center;
top: 100%;
margin-left: -5.3em;
}
.Nav ul ul li {
background-color: rgb(5, 90, 160);
border-top: medium solid rgba(0,115,209,1.00);
margin-right: -1em;
}
.Nav ul li:hover > ul {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="cNav">
<div class="Nav">
<ul>
<li>G</li>
<li>Home</li>
<li id="software">Software
<ul>
<li>Android</li>
<li>Windows</li>
</ul>
</li>
<li>Über</li>
</ul>
</div>
</nav>