Menu in CSS using <ol> - html

When I hover a Media, E-sport, Community I want to see <li> under them. I get it with the rgb opacity. But it's a pity that when I hover AN <li> element which is opacity 0 it appears. I only want to do it when I hover ol li a. Someone know's the answer?
Here's my code (Menu with lists)
.Menu ol {
display: inline-block;
padding: 0;
margin: 0;
line-height: 1;
}
.Menu ol>li>ul>li>a {
margin-left: 0;
padding: 0;
}
.Menu ol>li {
float: left;
padding: 0;
list-style-type: none;
}
.Menu ol>li>ul>li>a {
color: rgba(55, 255, 255, 0);
transition: .5s ease-in-out;
}
.Menu ol>li:hover>ul>li>a {
color: rgba(55, 255, 255, 1);
transition: .5s ease-in-out;
background-color: rgb(0, 0, 205, 1);
}
.Menu ol>li>ul>li {
clear: both;
margin-left: 90px;
}
.Menu ol>li>ul>li {
clear: both;
margin: 0;
list-style-type: none;
padding: 0;
}
.Menu ol>li>ul>li>a {
padding-left: 0;
margin: 0;
}
Article {
width: 1920px;
height: 957px;
}
<div class="Menu">
<ol>
<li>Media
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>E-sport
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>Community
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
</ol>
</div>

To be honest I find the whole ".Menu ol>li:hover>ul>li>a.. " and so on pure madness, its messy and unclear, much better effects you will get when using pure divs and classes, also use display: none, so it actually takes away the elements unless you set it to something, here is the code:
Edited: Use opacity: 0 and overflow: hidden, it works with transtition
Edit2: Actually simple height: 0 + overflow hidden will give you nice transtition in AND out, it got to have fixed height on hover thou.
<div class="Menu">
<div class="Menu-item-container">
Media
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
E-sport
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
Community
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
</div>
<style>
.Menu {
display: flex;
justify-content: space-around;
width: 300px;
}
a {
text-decoration: none;
}
.hover-items {
transition: .5s ease-in-out;
height: 0;
overflow: hidden;
}
.Menu-item-container {
width: 100px;
text-align: center;
}
.Menu-item-container:hover .hover-items{
height: 100px;
}
</style>
Codepen: https://codepen.io/Raitar/pen/QOZgoV?editors=1100

Dude i'm sorry but your code is madness. why combine ol and ul.
here i give you free mine :
body{
width:100%;
height:100%;
margin:0;
}
ul{
list-style:none;
padding:0;
}
a{
text-decoration:none;
}
.menu {
width:100%;
height: 33px;
background: #000;
position:relative;
}
.menu ul:not(.sub-menu):not(.micro){
margin:auto;
display:flex;
}
.menu ul li{
position:relative;
flex:1;
}
.menu a{
text-align:center;
display:block;
line-height: 33px;
margin-right: 40px;
color:#fff;
padding: 0 15px;
}
.sub-menu{
width:100%;
display:none;
position: absolute;
transform:translateY(0);
background: #ccc;
transition: all 300ms;
z-index:2;
}
.sub-menu a{
margin:10px 0;
}
.micro{
top:-10px;
width:100%;
opacity:0;
transform: translate(100%, 0);
position: absolute;
background: orangered;
z-index:1;
transition: all 300ms;
}
.micro a{
color:#fff;
}
.menu ul li a:hover + ul.sub-menu {
display:block;
}
.sub-menu:hover{
transform:translateY(5%);
display:block;
}
.sub-menu a:hover + ul.micro {
opacity:1;
}
.micro:hover{
opacity:1;
}
<div class="menu">
<ul>
<li>MEDIA
<ul class="sub-menu">
<li>FACEBOOK
<ul class="micro">
<li>TWITTER</li>
<li>TWITTER</li>
<li>TWITTER</li>
</ul>
</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>E-SPORT
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>COMMUNITY
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
</ul>
</div>

Related

Padding in the navbar while shifting the element

Hi I can't seem to be removing the background color after shifting elements. While the elements have moved and they are working perfectly but every timeenter image description here I am clicking on the sign in and sign up, the original space seems to show up as the background color.
HTML code:
<nav>
<ul>
<li><a class="active" href="#"><i class="fa fa-home" aria-hidden="true"></i>Home</a></li>
<li>Blog</li>
<li>Categories
<ul>
<li>Romance</li>
<li>Paranormal</li>
<li>Thriller</li>
<li>Horror</li>
</ul>
</li>
<li>Reviews
<ul>
<li>Star Rating 1</li>
<li>Star Rating 2</li>
<li>Star Rating 3</li>
<li>Star Rating 4</li>
<li>Star Rating 5</li>
</ul>
</li>
<li>Contest
<ul>
<li>Giveaways</li>
<li>Free Books for Reviews</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>For Authors</li>
<li>For Bloggers</li>
</ul>
</li>
<li><i class="fa fa-user-plus" aria-hidden="true"></i>Sign Up</li>
<li><i class="fa fa-fw fa-user"></i>Sign In</li>
</ul>
</nav>
CSS code:
/* navigation top menu */
nav{
position: relative;
top:0;
left:0;
padding: 5px 0 0 0;
width: 100%;
font-size: 1em;
}
.active
{
background-color: #F24F1B;
color: white;
}
nav::after{
content:'';
display: block;
clear:both;
}
nav ul{
list-style: none;
margin:0;
padding:0;
position: relative;
right: 200px;
}
nav ul li:hover {
background-color: #F24F1B;
}
nav ul li:hover > ul {
display: block;
}
nav ul li a {
display: inline-block;
color:black;
padding: 10px 20px;
text-decoration: none;
width: 125px;
position: relative;
}
nav ul li a:visited {
color:black;
}
nav ul li a .active{
color: white;
}
nav ul li a:hover {
background-color: #F24F1B;
color: white;
}
nav ul ul {
position: relative;
top: 100%;
background-color: #F24F1B;
display: none;
position: relative;
right: 0px;
}
nav ul ul li {
position: relative;
border-bottom: 2px solid rgb(128, 104, 104);
}
nav ul ul ul {
left: 100%;
top: 0px;
}
/* top level */
nav>ul {
padding-left: 200px;
color:white;
}
nav>ul>li {
float: left;
}
nav>ul>li>a {
width: auto;
padding: 10px 20px 15px 20px;
}
.signed {
position: relative;
left: 300px;
}
Your issue is because your background-color is on the li and not on a.signed but you are moving your a.signed with left: 300px; and not the li.
If you put the class .signed to the list item instead of the link, it will work as you'd expected.
Here's the code with the fix: https://codepen.io/MateoStabio/pen/rNWeYXd
I do recommend looking into restructuring your navigation entirely so that the right nav doesn't jump when you hover items on the left navigation.
.signed {
background-color: transparent;
position: relative;
left: 300px;
}
Try This one.

How to fix navbar dropdown menu in css

I have a problem with the dropdown menu when I hover in services menu. Here's the problem (on Codepen)
*{
margin: 0;
padding: 0;
}
body{
margin: 0 auto;
width: 800px;
}
a{
font-family: 'Alegreya Sans Regular';
}
#navigation{
height: 113px;
width: 800px;
background-color: #17384D;
}
.weblogo{
margin-top: 34px;
margin-left: 20px;
}
nav{
float: right;
margin-top: 60px;
margin-right: 60px;
}
nav ul ul{
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul li{
display: inline-block;
padding-left: 45px;
}
nav ul li a{
text-decoration: none;
list-style: none;
color: #FAD46B;
font-size: 1.3em;
}
.active{
border-bottom: 2px solid #FF972C;
padding-left: 0px;
}
<div id="navigation">
<img class="weblogo"src="weblogo.png"></img>
<nav>
<ul>
<li class="active">home</li>
<li>work</li>
<li>about</li>
<li class="dropdown">services
<ul>
<li>Search</li>
<li>Search</li>
<li>Search</li>
<li>Search</li>
</ul>
</li>
<li>contact</li>
</ul>
</nav>
Better way to create sub menus is this
Replace your html with this
HTML
<div id="navigation">
<img class="weblogo"src="weblogo.png"></img>
<nav>
<ul>
<li class="active">home</li>
<li>work</li>
<li>about</li>
<li class="dropdown"><a onClick="toggleNavPanel('panel')" >services</a>
<div id="panel">
<div>
<ul>
<li>Search</li>
<li>Search</li>
<li>Search</li>
<li>Search</li>
</ul>
</div>
</div>
</li>
<li>contact</li>
</ul>
</nav>
And add this to your css
#panel {
position: absolute;
background-color: red;
height: 0;
width: 100px;
top: 120px;
transition: height 0.3s linear 0s;
overflow:hidden;
}
Add this javascript also
function toggleNavPanel(x) {
var panel = document.getElementById(x), maxH="300px";
if(panel.style.height == maxH) {
panel.style.height = "0px";
}else {
panel.style.height = maxH;
}
}
Also remove this from your css
nav ul li:hover > ul {
display: block;
}

Show Submenu when hover

I'm new in jQuery and I need to show the submenu when the cursor hovers.
this is my code:
<li class="menu">
Qui sommes nous?
<ul class="submenu">
<li>Notre histoire</li>
<li>Notre philosophie</li>
</ul>
</li>
You can do that with css, using visbility style.
There is example :
ul
{
position:relative; /*need for properly .submenu positioning */
margin:0; padding:0;
}
li
{
list-style-type:none; /*remove style type (circles) for all li*/
}
.menu
{
display:inline-block;
}
/*submenu will be placed under parent li and hidden, until .menu is hovered*/
.submenu
{
visibility:hidden;
position:absolute;
top:100%;
}
/*on hover .menu, .submenu will be showed*/
.menu:hover > .submenu
{
visibility:visible;
}
<ul>
<li class="menu">
Qui sommes nous?
<ul class="submenu">
<li>Notre histoire</li>
<li>Notre philosophie</li>
</ul>
</li>
<li class="menu">
Qui sommes nous?
<ul class="submenu">
<li>Notre histoire</li>
<li>Notre philosophie</li>
</ul>
</li>
<ul>
This can be done using pure CSS. Try this:
.submenu {
height: 0;
width: auto;
background: url(../../../themes/images/...png) repeat;
position: relative;
top: 15px;
line-height: 11px;
}
.submenu li {
height: 12px;
font-size: 12px;
color: #FFF;
padding: 15px;
padding-right: 5px;
font-family: Arial, Helvetica, sans-serif;
display: none;
cursor: pointer;
}
.submenu li:hover {
color: #FFF;
background: #A526CA;
}

Child level <ul> height issue

I know it'll be sillest Question ever!!, but having a Query regarding the height of sub level <ul>, i am not getting the full height of child tag.
<div class="nav megaMenu">
<ul>
<li>Home</li>
<li>About Us
<ul class="sub-nav" >
<li class="sub-nav-col" >About us A
<ul class="sub-inner">
<li>About us A 1</li>
<li>About us A 2</li>
<li>About us A 3</li>
</ul>
</li>
</ul>
</li>
<li>Clients
<ul>
<li>Links A
<ul>
<li>Links C 1</li>
</ul>
</li>
<li>Links B
<ul>
<li>Links B 1</li>
<li>Links B 2</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>level-2</li>
<li>level-2</li>
<li>level-2</li>
</ul>
</li>
</ul>
</div>
CSS:
.nav {
float: left;
width: 100%;
}
.nav ul{
display:table;
margin: 0 auto;
max-width: 1024px;
width: 100%;
}
.nav > ul > li.level1{
position:static;
}
.nav ul li {
display: table-cell;
transition: all 0.5s ease 0s;
position: relative;
}
.nav li a {
transition: all 0.5s ease 0s;
display:block;
}
.nav > ul > li > a {
background: #f5f5f5;
border-right: 1px solid #000;
box-sizing: border-box;
display: block;
padding: 10px;
}
.nav > ul > li:last-child > a {
border-right: none;
}
.nav {
position: relative;
}
.nav.megaMenu > ul > li > ul{
left: 0;
position: absolute;
right: 0;
width: 100%;
z-index:9;
height:100%;
background:red;
}
.nav.megaMenu > ul {
position: relative;
margin: 0 auto;
max-width: 1024px;
}
.nav.megaMenu li.level2 ul li {
width:100%;
}
.nav.megaMenu > ul li:hover ul {
visibility:visible;
}
.nav > ul > li ul {
visibility:hidden;
z-index: 9;
position: absolute;
}
.nav > ul > li.level1 ul li a {
background: rgba(0, 0, 0, 0.2);
border-bottom: 1px solid #000;
box-sizing: border-box;
color: #fff;
display: block;
margin-right: 1px;
padding: 10px;
}
you can get the working demo # here. at here when you hover on menu, you will find the red background coloured <ul> which contains sub children too, but the height of <ul> is not covering the height of full heirarchy. please help me for this!
Remove the absolute parent on child ul since the parent is already in absolute position.
.nav > ul > li ul {
visibility:hidden;
z-index: 9;
}
Demo: fiddle

How do I put the menu next to the logo?

Screenshot of the header that's needing this work:
As you can see, the menu is below the logo. I was wanting the menu beside it, to the right of the logo. I don't know if it's possible, but if it is, I could use some help, please.
Here's the code for everything, separated for your convenience.
The menu and logo in their divs:
<div id="wrapper">
<div id="body-wrapper">
<div class="head">
<div class="head-wrapper">
<div class="logo">
<img src="http://i.imgur.com/sDnntOE.png">
<ul>
<li>Home</li>
<li>About Us
<ul>
<li>The Team</li>
<li>History</li>
</ul>
</li>
<li>Products
<ul>
<li>Chaotix Browser</li>
<li>Useful Beta 1.7.5</li>
<li>Chaotix Cleaner 1.4</li>
<li>Forum</li>
<li>CDev</li>
<li>Infinite-PVP</li>
<li>Ulta-Craft</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>E-Mail</li>
<li>News Letter</li>
<li>Social Mediar</li>
</ul>
</li>
<li>Divisions
<ul>
<li>Gaming</li>
<li>Films</li>
</ul>
</li>
<li>Chaotix! Forum</li>
<li>Partnerships
<ul>
<li>GameFanShop</li>
<li>Forumotion</li>
</ul>
</li>
</ul>
The CSS:
<style>
*{
background-image:url('http://i.imgur.com/0u7sBsT.png');
background-color:#999999;
font-family:Tahoma;color:white;
}
div.head{
text-align:Center;
padding-top:10px;
}
div.body{
padding-top:100px;
padding-left:300px;
padding-right:300px;
text-align:center;
}
div.logo{
float:left;
}
a{
color:white;
}
a:hover{
color:gray;
}
/* Main menu
------------------------------------------*/
ul{
font-family: Lato,Tahoma,Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
padding-left:25px;
}
ul li{
display: block;
position: relative;
float: left;
}
li ul{
display: none;
}
ul li a{
display: block;
text-decoration: none;
color: #FFFFFF;
border-top: 1px solid #000000;
padding: 5px 15px 5px 15px;
background: #000000;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover{
background: #999999;
}
li:hover ul{
display: block;
position: absolute;
}
li:hover li{
float: none;
font-size: 11px;
}
li:hover a{
background: #000000;
}
li:hover li a:hover{
background: #999999;
}
</style>
Add your css
.logo img
{
float:left;
}
.logo ul
{
float:left;
}
It working ok. Hope this help!