Hover to view animation on a link with CSS - html

I am trying to create an effect on a website like this one: http://www.cssplay.co.uk/menu/css3-animation.html#x . My code only uses two images at the moment but I'll be using about 10 to 15 for the final animation. I'm trying to achieve the hover to view animation, the second image,not the click effect. Here's the code:
.footer nav ul.homeandlist li {
display: block;
width: 40%;
height: 150px;
float: left;
margin: 1% 3%;
background-color: rgba(255, 165, 0, 0.11);
}
.footer nav ul.homeandlist a {
margin: 0;
padding: auto;
width: 100%;
height: 90px;
text-indent: -9000px;
line-height: 2em;
font-size: 16px;
display: block;
}
.footer nav ul.homeandlist .GetOnList {
position: relative;
width: 40%;
height: 150px;
}
.footer nav ul.homeandlist .GetOnList a {
display: block;
-webkit-transition: z-index 0.1s linear;
transtion: z-index 0.1s linear;
}
.footer nav ul.homeandlist .GetOnList a#a1 {
background: url('images/image1.png');
}
.footer nav ul.homeandlist .GetOnList a#a2 {
background: url('images/image2.png');
}
.footer nav ul.homeandlist .hover a:hover {
z-index: 20;
}
.footer nav ul.homeandlist .hover a:hover + a {
z-index: 30;
}
.footer nav ul.homeandlist .hover a#a1 {
z-index: 20;
}
.footer nav ul.homeandlist .hover a#a2 {
z-index: 10;
}
<div class="footer">
<nav>
<p class="footertext">Text will go here</p>
<div class="clear"></div>
<ul class="homeandlist">
<li class="GetOnList hover">
<a id="a1" href="GetOnList.html">Get On List</a>
<a id="a2" href="GetOnList.html">Get On List</a>
</li>
<li class="HomeLink">HomeLink
</li>
</ul>
</nav>
</div>
So far only image 1 shows up but nothing happens on hover. To me it looks like I'm using the same code as what's used on the website. Any ideas?
I've edited the code to remove parts that may not matter. If more code is needed let me know and I can include what you need, but this should cover it.

Here's a new example: http://jsbin.com/wixume/5/edit
The code uses selectors to
MARK UP:
<div class="footer">
<nav>
<ul class="homeandlist">
<li id="addedId"><a id="a1">Get On List</a></li>
<li id="anotherAddedId"><a id="a2">Get On List</a></li>
<li id="lastOne"><a id="a3">Get On List</a></li>
</ul>
</nav>
</div>
CSS:
.footer nav ul.homeandlist li {
display: block;
}
.footer nav ul.homeandlist a {
width: 100%;
height: 90px;
display: block;
}
a{
position:absolute;
}
.footer nav ul.homeandlist li {
position: absolute;
width: 40%;
height: 150px;
}
.footer nav ul.homeandlist li {
display: block;
-webkit-transition: z-index 0.9s linear;
transtion: z-index 0.9s linear;
}
#a1 {
background-color: red;
}
#a2 {
background-color: yellow;
}
#a3 {
background-color: blue;
}
#addedId:hover {
/* Move the first one to the bottom when hover*/
z-index: 9;
}
li:hover + li {
/*
Move the second li to the top
If move mouse, the element below it gets selected and moved to the top.
...and so on for each one below that...
Once are hovering on the bottom one and we move,
nothing for a moment has a hover state so we can see the top li.
And then it starts all back over.
*/
z-index: 30;
}
#addedId {
z-index: 20;
}
#anotherAddedId {
z-index: 19;
}
#lastOne:{
z-index:10;
}

Related

How to fix this dropdown navbar

I am writing a navigation bar with a dropdown option.
I have 2 problems: I can't get the dropdown to position properly under the menu, + also when I try to move the mouse to click on the elements in the dropdown submenu it closes as soon as I move.
Can anyone suggest a fix?
Thanks
On codepen:
https://codepen.io/-royqooe/pen/GRxaVbm
/* CSS section for home */
.navtop {
position: relative;
background-color: #333333;
height: 50px;
width: 100%;
border: 0;
}
.navtop div {
display: flex;
margin: 0 auto;
height: 100%;
}
.navtop div h1,
.navtop div a {
display: inline-flex;
align-items: center;
}
.navtop div h1 {
flex: 1;
font-size: 24px;
padding: 0;
margin: 0;
margin-left: 2%;
color: #f5f8ff;
font-weight: normal;
}
.navtop div a {
padding: 0 12px;
text-decoration: none;
color: #c1c4c8;
font-weight: bold;
}
.navtop div a i {
padding: 2px 8px 0 0;
}
.navtop div a:hover {
color: #66ccff;
}
/* sequel for home and navbar */
nav.navtop {
font-family: monospace;
}
.navtop>.navbar>ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.navtop li {
display: block;
float: left;
padding: 0.5rem 0;
position: relative;
text-decoration: none;
transition-duration: 0.3s;
}
.navtop ul li ul {
background: red;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
.navtop ul li:hover>ul,
.navtop ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
.navtop ul li ul li {
clear: both;
width: 100%;
}
#media screen and (max-width: 760px) {
.topbar-text {
display: none;
}
}
<nav class="navlol navtop" role="navigation">
<div class="navbar">
<h1>Websitee Title</h1>
<ul>
<li><i class="fa-solid fa-file"></i><span class="topbar-text">Home</span></li>
<li>Two
<ul class="dropdownnn">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li class="navelements">Three</li>
<li><i class="fas fa-user-circle"></i><span class="topbar-text">Profile</span></li>
<li><i class="fas fa-sign-out-alt"></i><span class="topbar-text">Logout</span></li>
</ul>
</div>
</nav>
got an easy fix for you:
add this
.navtop li {
min-height:25px;
}
the issue is that that menu li was way shorter than the others to the sides due to the icons, even better maybe is instead adding this instead:
.navtop li {
height:100%
}
both worked for me
In the screenshot, the yellow color is the area that <li> element is covering. You can see there is a gap between <li> element and submenu. When you try to move the mouse to submenu, your cursor goes out of yellow area and the submenu hides.
The solution would be to position the submenu so it starts exactly after yellow area and make sure there is no gap. Apply margin-top of 0.5rem on submenu instead of 1rem.

CSS Vertical Menu with submenu callouts overlapping

Its been a while - but I found myself a new exiting hobby in web development, and I am hoping that you can help me overcome the following issue:
I am working on a personal website. Content etc. is all preliminary. My main focus is the vertical menu on the left hand side. While I am pretty happy with the appearance so far, there are still some questions:
1) I had to set the transition as ease out to >0s, so that I have enough time between the main-menu hover and the hover over the sub-menu. Because of this, if I hover between main-menu items, they will briefly overlap due to the phase out. Is there a way to work around this?
(the focus selector might be an option, but that requires to click the menu item, and I prefer the hover)
2) The sub-menu is aligned to the top of the li of the main-menu. Because of that, the last item's sub (Testing) exceeds the boundaries of the page, giving whitespace below the page. Is there a way to make the sub-menu shift up if it presses against the edge of the overall body?
I probably could give it a different tag and design it differently, am I am hoping there is a more general solution.
3) Minor issue: When switching from main-menu hover to sub-menu hover, the main-icon "blinks" very briefly. Is that normal behavior? Certainly isn't pretty.
4) Last but not least: As this is my first time doing a website, I would be more than grateful to get your general feedback on inefficiencies in the code, so I can be more lean in the future.
(see updated fiddle below - full code removed to save space.)
Thanks for your help!
EDIT
THanks for your answers - issue #1 has been solved using the approaches you outlined!
However, the last submenu still gives me a bit a headache.
If I use the "last-child" selector, and the code added below, it will not change anything. However, if I give the last "bubble" a different tag, using the exact same code, the bubble will align to the bottom of the last main-menu item, but the containing UL remains defiant.
As you can see from the original CSS, the last "relative" is the main-menu IL, so shouldn't the submenu and the containing UL both align to the bottom of their respective parent/grandparent?
using a dedicated, different tag for the last-child "bubble_last
Using the last-child selector
and the accompanying new code (updated fiddle with full code: Heres the Fiddle ...use large screen for the result to see the alignment issue):
.navigation ul li:last-child {
border: solid orange;
}
.navigation .bubble_last{
position: absolute;
margin-top: 0%;
padding: 0px;
left: 60px;
bottom: 0px;
width: 400px;
height: 200px;
border: solid red;
}
.navigation .bubble_last ul{
position: absolute;
left: 0;
bottom: : 0px;
margin-top: 0px;
padding: 0px;
width: 20vw;
height: 100px;
font-size: 15px;
font-size: 1.2vw;
font-weight: 400;
border: solid blue;
margin-left: 28%;
display: block;
}
.navigation .bubble_last ul li {
list-style: none;
background-color: none;
border-radius: 3px;
height: 2vw;
line-height: 1.2vw;
width: 20vw;
position: relative;
padding-top: 0px;
margin: 0;
padding: 0;
}
Instead of adding a transition delay on .bubble, you just need to make the .bubble class wide enough (and start behind the main li trigger with a left: 60px) so that the hover will be continuous:
.navigation .bubble {
position: absolute;
margin-top: 0%;
padding: 0px;
left: 60px;
top: 0px;
width: 200px;
height: 100%;
background-color: none;
}
Then just add a margin-left to the submenu:
.navigation ul li ul {
margin-left: 20px;
}
To fix your second issue, simply add the following CSS to make the last submenu positioned relative to the bottom of the nav item:
ul li ul.subm:last-child {
top: auto;
bottom:0px;
}
Updated Demo: JSFiddle
How about this? Adjust your navigation to use the nav element, set it to use flex box, adjust that so it fits the height of your page, and then adjust the transition effects so they transition in and out properly.
I hope this helps.
#import url("http://fonts.googleapis.com/css?family=Roboto");
* {
border: none;
margin: 0;
padding: 0;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: Roboto Condensed;
box-sizing: border-box;
}
.landing {
display: table;
margin: auto;
width: 100%;
height: 100%;
background: url("https://imageshack.com/i/poXkyeIYj") 50% 50% no-repeat;
background-size: cover;
top: 0;
position: relative;
z-index: 1;
}
.landing .welcome {
margin: 10px;
width: 89%;
color: #FFF;
text-align: center;
display: table-cell;
vertical-align: middle;
position: absolute;
left: 10%;
top: 30%;
}
#mug {
background: url("https://imageshack.com/i/pmJaAuFkj") 50% 50% no-repeat;
background-size: cover;
border: solid 3px #FFF;
/*max-width: 20%;
max-height: 20%; */
width: 150px;
height: 150px;
margin: auto;
border-radius: 100%;
}
nav {
width: 50px;
height: 100%;
flex: 1;
display: flex;
justify-content: center;
flex-direction: column;
}
nav img {
max-width: 50px;
max-height: 50px;
}
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
-ms-flex: 0 100px;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
justify-content: space-between;
margin-top: 0px;
padding: 0px;
width: 11vw;
height: auto;
font-size: 15px;
font-size: 1.2vw;
font-weight: 400;
border-color: none;
}
nav ul li {
background-color: rgba(222, 225, 229, 0.8);
border-radius: 3px;
width: 100%;
font-size: 15px;
font-size: 1.2vw;
font-weight: 900;
}
.nav ul:before,
.nav ul:after {
content: "";
display: block;
}
.nav ul:after {
clear: both;
}
.nav ul>li {
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
text-decoration: none;
color: #FFF;
}
.nav a:hover {
text-decoration: none;
background-color: rgba(242, 93, 38, 0.8);
}
.nav li ul {
background: #273754;
}
.nav li ul li {
width: 200px;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav li ul {
position: absolute;
left: 11vw;
top: 0;
z-index: 1;
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 200ms ease;
-moz-transition: 200ms ease;
-o-transition: 200ms ease;
transition: 200ms ease;
}
.nav ul>li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
span.caption {
display: none;
}
<body>
<div class="landing">
<div class="welcome">
<div id="mug">
</div>
<h1>Welcome to my personal Website!</h1>
<h2>On this site you will find a information about the person, the profession and other stuff about me. Enjoy!</h2>
</div>
<!-- cleaned up the navigation, nested it within the rest of the page, and adjusted the css -->
<nav class="nav">
<ul>
<li>
<img src="https://imageshack.com/i/potj2pVwp"> <span class="caption">Home</span>
</li>
<li>
<img src="https://imageshack.com/i/pntQ9nVMp"><span class="caption">About Me</span>
<ul>
<li>What I do</li>
<li>Motorcycling</li>
<li>Music</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/po4WFq6Yp"><span class="caption">Professional</span>
<ul>
<li>Current Employment</li>
<li>Working Experience</li>
<li>Education</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pmcfm7Kbp"> <span class="caption">Projects</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pnM0Fmgrp"> <span class="caption">Misc</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/poqRnk6ap"> <span class="caption">Testing</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pmc8tts9p"> <span class="caption">Contact</span>
</li>
</ul>
</nav>
</div>

CSS Animation on Sidebar Submenu

I've been trying to figure this out, but I'm honestly lost. I'm making a sidebar that has three levels: a main menu, with two more submenus when you hover over the menu items(so it's main menu item > submenu item > another submenu). The thing is, I'm not very good with CSS animations, but I'm trying to learn. And was wondering if this could be done with it?
Here's my code so far. Initially, I started this out with JS, but stackoverflow told me it'd be easier to do it with CSS animation. And honestly, this looks way cleaner. Anyway, currently, it shows the icon titles beside it when you hover over a sidebar. But how exactly should I go about making the submenu appear when you hover over each menu item separately? Should I do it by having a whole new div appear on hover, or should I do it by expanding the existing one(this doesn't seem like it'd be a good idea)?
What's the correct way? And on which elements should I add CSS transitions to achieve that smooth slidein sidebar?
/* .subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
}
my poor attempt at submenu */
.sidebar {
margin-top: 75px;
position: fixed;
width:75px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 160px;
}
.sidebar ul {
width:200px;
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
<div class="sidebar">
<ul class="nav flex-column m-0">
<li class="nav-item py-2">
<a class="nav-link" href="#">
<i class="fa fa-envelope-open" aria-hidden="true"></i>
<span class="pl-1">
Item
</span>
</a>
<ul class="nav subnav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
Overview
<span class="sr-only">
(current)
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Analytics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Export</a>
</li>
</ul>
</li>
</ul>
</div>
Thank you!
I hope this will help you. Here is some modification in your previous code.
You can also check it on Jsfiddle
*
{
color: #fff;
}
/* .subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
}
my poor attempt at submenu */
.sidebar {
margin-top: 75px;
position: fixed;
width:20px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 250px;
}
.sidebar ul {
width:200px;
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
/* reset our lists to remove bullet points and padding */
.mainmenu, .submenu, .submenu1 {
padding: 0;
margin: 0;
}
/* make ALL links (main and submenu) have padding and background color */
.mainmenu a {
display: block;
text-decoration: none;
padding: 10px;
}
/* add hover behaviour */
.mainmenu a:hover {
background-color: #C5C5C5;
}
.mainmenu li:hover .submenu {
display: block;
max-height: 200px;
}
.submenu li:hover .submenu1 {
display: block;
max-height: 200px;
}
.submenu a
{
}
.submenu li
{
padding-left: 15px;
}
.submenu1 a
{
}
.submenu1 li
{
padding-left: 20px;
}
/* hover behaviour for links inside .submenu */
.submenu a:hover {
background-color: #666;
}
/* this is the initial state of all submenus.
we set it to max-height: 0, and hide the overflowed content.
*/
.submenu,
.submenu1{
overflow: hidden;
max-height: 0;
-webkit-transition: all 0.5s ease-out;
}
<div class="sidebar">
<ul class="nav flex-column m-0">
<li class="nav-item py-2">
<a class="nav-link" href="#">
<i class="fa fa-envelope-open" aria-hidden="true"></i>
<span class="pl-1">Item</span>
</a>
<nav class="navigation">
<ul class="mainmenu">
<li><span class="sr-only"></span>Home</li>
<li>About
<ul class="submenu">
<li>Team</li>
<li>Contact Us
<ul class="submenu1">
<li>Phone</li>
<li>Email</li>
<li>Fax</li>
</ul>
</li>
</ul>
</li>
<li>Our Products</li>
</ul>
</nav> </li>
</ul>
</div>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Multi-Level Drop Down Menu with Pure CSS</title>
<style>
ul {
list-style: none;
padding: 0;
margin: 0;
background: #1bc2a2;
}
ul li {
display: block;
position: relative;
float: left;
background: #1bc2a2;
}
/* This hides the dropdowns */
li ul { display: none; }
ul li a {
display: block;
padding: 1em;
text-decoration: none;
white-space: nowrap;
color: #fff;
}
ul li a:hover { background: #2c3e50; }
/* Display the dropdown */
li:hover > ul {
display: block;
position: absolute;
}
li:hover li { float: none; }
li:hover a { background: #1bc2a2; }
li:hover li a:hover { background: #2c3e50; }
.main-navigation li ul li { border-top: 0; }
/* Displays second level dropdowns to the right of the first level dropdown */
ul ul ul {
left: 100%;
top: 0;
}
/* Simple clearfix */
ul:before,
ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
ul:after { clear: both; }
</style>
</head>
<body>
<ul class="main-navigation">
<li>Front End Design
<ul>
<li>HTML</li>
<li>CSS
<ul>
<li>Resets</li>
<li>Grids</li>
<li>Frameworks</li>
</ul>
</li>
<li>JavaScript
<ul>
<li>Ajax</li>
<li>jQuery</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1>Multi-Level Drop Down Menu with Pure CSS</h1>
<div class="css-script-ads"><script type="text/javascript"><!--
google_ad_client = "ca-pub-2783044520727903";
/* CSSScript Demo Page */
google_ad_slot = "3025259193";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="//pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46156385-1', 'cssscript.com');
ga('send', 'pageview');
</script>
</body>
</html>
Hope it helps you. Please check it out and let me know.
Just modified your css a bit. Check if this helps. jsfiddle
.subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
opacity:0;
overflow:hidden;
}
.sidebar {
margin-top: 75px;
position: fixed;
width:75px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 160px;
}
.sidebar .subnav
{
transform:75px;
transition: transform .5s;
}
.sidebar:hover .subnav{
transform: translateX(85px)
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
.nav-item:hover .subnav {
opacity: 1;
}

how to add sub menus on a responsive css menu

I have this html for my css menu:
<nav class="clearfix">
<ul class="clearix">
<li>Homepage</li>
<li>Services</li>
<li>Project Gallery</li>
<li>Contact Us</li>
</ul>
Menu
</nav>
nav {
height: 50px;
width: 100%;
background: #F00;
font-size: 14pt;
font-family: Arial;
position: relative;
border-bottom: 5px solid #FFFFFF;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 100%;
height: 50px;
text-align: center;
}
nav li {
display: inline;
}
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav a {
color: #FFFFFF;
display: inline-block;
width: auto;
text-align: center;
text-decoration: none;
line-height: 50px;
}
nav li a {
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
padding-left: 10px;
padding-right: 10px;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #000000;
color:#FFFFFF;
}
nav a#pull {
display: none;
}
#media screen and (max-width: 600px) {
nav {
height: auto;
}
nav ul {
width: 100%;
display: block;
height: auto;
}
nav li {
width: 50%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
#media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
display: block;
color:#FFFFFF;
background-color: #F00;
width: 100%;
position: relative;
}
nav a#pull:after {
content:"";
background: url('nav-icon.png') no-repeat;
width: 30px;
height: 30px;
display: inline-block;
position: absolute;
rightright: 15px;
top: 10px;
}
}
#media only screen and (max-width : 320px) {
nav li {
display: block;
float: none;
width: 100%;
}
nav li a {
border-bottom: 1px solid #FFFFFF;
}
}
I am looking for a way to add sub menus and then second sub menus on on the first ones but still keep it as responsive as it is.
How can I do this?
http://jsfiddle.net/EYjnG/
JSFIDDLE DEMO
logic is just simple and have with this code
#submenu,#submenu2,#submenu3{
visibility:hidden; /*turn all the submenus visibility hidden */
}
#top_menu li.first:hover #submenu,#submenu li.second:hover #submenu2,#submenu2 li.second:hover #submenu3{
visibility:visible; /*On hover turn on visibility visible */
}
Complete code :
HTML:
<div id="top_menu"> <!--MAIN MENU -->
<ul>
<li class="first">menu1
<div id="submenu"> <!--First Submenu -->
<ul class="abc">
<li class="second">item1
<div id="submenu2"> <!--Second Submenu -->
<ul class="abc">
<li class="second">item1_1
<div id="submenu3"> <!--Third Submenu -->
<ul class="abc">
<li class="second">item1_1_1</li>
<li class="second">item1_1_2</li>
<li class="second">item1_1_3</li>
</ul>
</div> <!--third Submenu Ends here-->
</li>
<li class="second">item1_2</li>
<li class="second">item1_3</li>
</ul>
</div> <!--Second Submenu Ends here-->
</li>
<li class="second">item2
<div id="submenu2">
<ul class="abc">
<li class="second">item2_1</li>
<li class="second">item2_2</li>
<li class="second">item2_3</li>
</ul>
</div>
</li>
<li class="second">item3
<div id="submenu2">
<ul class="abc">
<li class="second">item3_1</li>
<li class="second">item3_2</li>
<li class="second">item3_3</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="first">menu2
<div id="submenu">
<ul class="abc">
<li class="second">item1</li>
<li class="second">item2</li>
<li class="second">item3</li>
<li class="second">item4</li>
</ul>
</div>
</li>
</ul>
</div>
CSS:
ul{
padding:10px;
padding-right:0px;
}
li.first{
display:block;
display:inline-block;
padding:5px;
padding-right:25px;
padding-left:25px;
cursor:pointer;
}
li.second{
list-style:none;
margin:0px;
padding:5px;
padding-right:25px;
margin-bottom:5px;
cursor:pointer;
}
#submenu li.second:hover{
background:red;
border-radius:5px;
}
#submenu2 li.second:hover{
background:green;
border-radius:5px;
}
/*********MAIN LOGIC***************/
#submenu,#submenu2,#submenu3{
visibility:hidden;
}
#top_menu li.first:hover #submenu,#submenu li.second:hover #submenu2,#submenu2 li.second:hover #submenu3{
visibility:visible;
}
/**********STYLING SUBMENUS**************/
#submenu{
padding-right:0px;
text-align:left;
position:absolute;
background:white;
box-shadow:0px 0px 5px;
border-radius:5px;
}
#submenu2{
text-align:left;
position:absolute;
left:70px;
top:0px;
background:red;
box-shadow:0px 0px 5px;
border-radius:5px;
}
#submenu3{
text-align:left;
position:absolute;
left:80px;
top:0px;
background:green;
box-shadow:0px 0px 5px;
border-radius:5px;
}
just understand the logic behind this code and you can made as many submenus as you want.
There are many ways to go ahead about this.
I usually hide the sub menu uls with display: none and take them out of the content flow with position: absolute. Give the li containing the sub menu position: relative so that the sub menus are relative to their direct parents, then position the sub menus however you please using the top, right, bottom and left properties. Finally, change the sub menu to display: block through a :hover or whatever.
Here's a bare-bones example of this:
Markup:
<nav>
<ul>
<li><a>Link</a>
<ul>
<li><a>Sub link</a></li>
<li><a>Sub link</a></li>
<li><a>Sub link</a></li>
</ul>
</li>
</ul>
</nav>
CSS:
nav li {
position: relative;
}
nav li > ul {
position: absolute;
top: 100%;
display: none;
}
nav li:hover > ul {
display: block;
}
Here's a pen with this example. It looks like crap but you get the drill.
You can just keep nesting more sub-menus, but you'll probably want to use different positioning for second-and-lower-levels of sub menus.
However, please note that mobile browsers don't really support :hover. At least they don't treat it the same. You shouldn't make your sub menus accessible only on :hover. Consider adding some sort of class name toggle on click with javascript instead.
use hover in css like:
a:hover
or if your div id is "div1":
#div1:hover
I am not 100% sure if your asking how to make the id menu have a menu functionality or just a sub menu for your main nav.
If it is pertaining to a sub menu for your main nav then this will work just fine. If it's for the mobile menu then let me know and I'll work something out for you. (SOLVED)
This fiddle has the sub menu working while still being responsive the entire time. You can style it to your needs but it is a solid start.
nav ul li ul {
display: none;
position: absolute;
width: 100%;
top: 100%;
background: #000;
color: #fff;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
display: block;
-webkit-transition: .6s ease;
-moz-transition: .6s ease;
-ms-transition: .6s ease;
-o-transition: .6s ease;
}
nav ul li ul li:hover {
background: #c1c1c1;
color: #2b2b2b;
}
JSFIDDLE
JSFIDDLE with relative sized sub menu
Here is the mobile navigation working and the biggest problem was you had no jQuery library selected for the fiddle to run off of.
Mobile Nav
HTML
<div id="pull"><span>Menu</span>
</div>
CSS
div span {
color: #FFFFFF;
display: inline-block;
width: auto;
text-align: center;
text-decoration: none;
line-height: 50px;
padding-left: 10px;
padding-right: 10px;
}
I changed the id pull to a div because when it was an anchor tag all of the navs would lose their text color.
I have made a drop-down with a drop-down in it while still being responsive! Take a peak at this jsfiddle.
JSFIDDLE Drop-Down with a nested Drop-Down
Here's my take: http://codepen.io/teodragovic/pen/rmviJ
HTML
<nav>
<input type="checkbox" id="nav-toggle-1" />
<label for="nav-toggle-1" class="pull sub"><a>Menu</a></label>
<ul class="lvl-1">
<li>Homepage</li>
<li>
<input type="checkbox" id="nav-toggle-2" />
<label for="nav-toggle-2" class="sub"><a>Services</a></label>
<ul class="lvl-2">
<li>Service 1</li>
<li>Service 2</li>
<li>
<input type="checkbox" id="nav-toggle-3" />
<label for="nav-toggle-3" class="sub"><a>Service 3</a></label>
<ul class="lvl-3">
<li>Service 3 a</li>
<li>Service 3 b</li>
</ul>
</li>
<li>Service 4</li>
</ul>
</li>
<li>Project Gallery</li>
<li>Contact Us</li>
</ul>
</nav>
CSS
#import "compass";
/* globals */
* {box-sizing:border-box;}
ul {
margin: 0;
padding: 0;
}
input {
position: absolute;
top: -99999px;
left: -99999px;
opacity: 0;
}
nav {
height: 50px;
background: #F00;
font: 16px/1.5 Arial, sans-serif;
position: relative;
}
a {
color: #FFFFFF;
display: inline-block;
text-decoration: none;
line-height: 50px;
padding: 0 20px;
&:hover,
&:active {
background-color: #000000;
color:#FFFFFF;
}
}
/* nav for +600px screen */
ul.lvl-1 {
text-align: center;
#include pie-clearfix;
li {
display: inline;
}
}
ul.lvl-2,
ul.lvl-3 {
position: absolute;
width: 100%;
background: lighten(red, 15%);
display:none;
}
ul.lvl-3 {background: lighten(red, 30%);}
#nav-toggle-2:checked ~ ul.lvl-2,
#nav-toggle-3:checked ~ ul.lvl-3 {
display: block;
}
.pull {display: none;}
/* arrow thingy - crappy positioning, needs tinkering */
.sub {
position: relative;
cursor: pointer;
&:after {
position: absolute;
top: 40%;
right: 0;
content:"";
width: 0;
height: 0;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
border-top: 6px solid white;
}
}
/* medium-ish nav */
#media screen and (max-width: 600px) {
nav {height: auto;}
a {
text-align: left;
width: 100%;
text-indent: 25px;
border-bottom: 1px solid #FFFFFF;
}
ul > li {
width: 50%;
float: left;
&:nth-of-type(odd) {
border-right: 1px solid white;
}
}
li:nth-of-type(even) ul.lvl-2,
li:nth-of-type(even) ul.lvl-3 {
position: relative;
width: 200%;
left: -100%;
}
li:nth-of-type(odd) ul.lvl-2,
li:nth-of-type(odd) ul.lvl-3 {
position: relative;
width: 200%;
left: 1px;
}
ul.lvl-2 li {background: lighten(red, 15%);}
ul.lvl-3 li {background: lighten(red, 30%);}
}
/* small-ish nav */
#media only screen and (max-width : 480px) {
.pull {
display: block;
width: 100%;
position: relative;
}
ul {
height: 0;
> li {
width: 100%;
&:nth-of-type(odd) {
border-right: none;
}
}
}
#nav-toggle-1:checked ~ ul.lvl-1 {
height: auto;
}
#nav-toggle-2:checked ~ ul.lvl-2,
#nav-toggle-3:checked ~ ul.lvl-3 {
//reverting stuff from previous breakpoint
left: 0;
width: 100%;
}
}
Markup is little modified from original since I find it easier to use classes than general selectors, especially when nesting lists.
It's CSS only (I'm using SASS+compass). :checked pseudo-class are used for toggling menus on and off. I removed link for services assuming that it will be used just for opening sub-menu (content-wise, you could always add something like "all services" in submenu if you want to keep that page in navigation).
Biggest challenge was styling middle breakpoint. Depending on position of parent list item (odd or even), child list is stretched to 200% (because parent is 50% wide) and positioned so it floats from left side. Small bug appears on level 3 regarding width of the list causing color bleed on edges.
Additionaly, display: block and display:none selectors could be replaced with max-height to add some cool css animation effects

Changing body background color using only HTML5 and CSS3..?

Is it possible to achieve the same effect found here: www.lutmedia.com simply using CSS3 and HTML5...and not jquery..? Where the body background color changes on hover over the list item links..?
Yes, you could get an effect like that with pure CSS, but it won't be the body changing background, but a last list item in that menu which has position: fixed and covers the entire page.
QUICK DEMO
Relevant HTML:
<ul class='menu'>
<li><a href='#'>contact</a></li>
<li><a href='#'>blog</a></li>
<!-- and so on, menu items -->
<li class='bg'></li>
</ul>
Relevant CSS:
.menu li { display: inline-block; }
.menu li:first-child a { color: orange; }
.menu li:nth-child(2) a { color: lime; }
/* and so on for the other menu items */
.menu:hover li a { color: black; }
.menu li a:hover { color: white; }
.bg {
position: fixed;
z-index: -1;
top: 0; right: 0; bottom: 0; left: 0;
background: dimgrey;
transition: .5s;
pointer-events: none;
}
.menu li:first-child:hover ~ .bg { background: orange; }
.menu li:nth-child(2):hover ~ .bg { background: lime; }
/* and so on for the other menu items */