Basically the navigation bar on my page is aligned to right hand side of the page with the logo on its left. Because of this when the drop down for the far right item appears, it drifts off the right side of the page and looks messy. Especially as it's using an aplha background.
Anyway, here is my code at the moment..
HTML:
<ul class="Nav2">
<li>
Category 1
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 2
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 3
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 4
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 5
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
</ul>
CSS:
ul.Nav2 {
list-style-type:none;
margin:0 auto;
padding:0;
overflow:hidden;
width:auto;
}
ul.Nav2 li {
float:right;
}
ul.Nav2 li a {
font-family:"Orator Std";
font-size:16px;
color:#000;
display:block;
width:auto;
height:20px;
line-height:20px;
border-left:1px Solid rgba(0,0,0,255);
background-color:#CCC;
text-align:center;
text-decoration:none;
opacity:0.6;
padding:0px 10px;
-webkit-transition:all 0.2s ease-in-out;
-moz-transition:all 0.2s ease-in-out;
-ms-transition:all 0.2s ease-in-out;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
ul.Nav2 li a:hover {
opacity:1;
}
ul.Nav2 ul {
list-style:none;
position:absolute;
left:-9999px;
text-align:right;
}
ul.Nav2 ul li {
padding-top:1px;
float:none;
}
ul.Nav2 ul a {
white-space:nowrap;
}
ul.Nav2 li:hover ul {
left:inherit;
}
ul.Nav2 li:hover a {
background:#FFF;
text-decoration:none;
}
ul.Nav2 li:hover ul a {
text-decoration:none;
}
ul.Nav2 li:hover ul li a:hover {
background:#FFF;
}
Basically this is how I WANT it to look....
Category 1 Category 2 Category 3 Category 4 Category 5
Item 1 Item 1 Item 1 Item 1 Item 1
Item 2 Item 2 Item 2 Item 2 Item 2
Rather than...
Category 1 Category 2 Category 3 Category 4 Category 5
Item 1 Item 1 Item 1 Item 1 Item 1
Item 2 Item 2 Item 2 Item 2 Item 2
(It's actually pushed to the right slightly but not centered to the parent <ul> <li>)
The width MUST be set to auto because of the huge range in widths between the text that is gunna be stored in the navigation bar. Some are about 100px and some are nearly 300px
Here's the fixed CSS. Removed and added styles are commented.
ul.Nav2 {
list-style-type:none;
margin:0 auto;
padding:0;
overflow:hidden;
width:auto;
}
ul.Nav2>li {
float:right;
}
ul.Nav2 li a {
font-family:"Orator Std";
font-size:16px;
color:#000;
display:block;
width:auto;
height:20px;
line-height:20px;
border-left:1px Solid rgba(0,0,0,255);
background-color:#CCC;
/*removed
text-align:center;
*/
text-decoration:none;
opacity:0.6;
padding:0px 10px;
;
;
;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
ul.Nav2 li a:hover {
opacity:1;
}
ul.Nav2 ul {
list-style:none;
position:absolute;
left:-9999px;
text-align:right;
float:right
/*added*/
display:block;
padding:0;
min-width:9.3ex;
}
ul.Nav2 ul li {
padding-top:1px;
float:none;
}
ul.Nav2 ul a {
white-space:nowrap;
}
ul.Nav2 li:hover ul {
left:inherit;
}
ul.Nav2 li:hover a {
background:#FFF;
text-decoration:none;
}
ul.Nav2 li:hover ul a {
text-decoration:none;
}
ul.Nav2 li:hover ul li a:hover {
background:#FFF;
}
EDIT: Updated CSS based on new restriction.
Related
I am trying to move #nav-bar elements to the right but it's not working. I want to put .logo to the left using flex-start but I don't think that's working. I think it's on the left by default.
I am new to css and html.
I tried making it into a flex box and using flex-end. I dont want to use inline or blocking. From what I understand, making display to flex and using flex-end will put the item to the right in a set row flex-direction .
*{
box-sizing: border-box;
margin:0;
padding:0;
}
body{
background-color:#b6eaf1;
font-family:Cambria, sans-serif;
}
header{
display:flex;
top:0;
width:100%;
border:5px solid blue;
}
.logo img{
width:17vw;
display:flex;
justify-content:flex-start;
align-items:center;
}
img{
height:100%;
width:100%;
}
#nav-bar{
display:flex;
}
#nav-bar ul{
list-style:none;
display:flex;
flex-direction:row;
justify-content:flex-end;
height:100%;
gap:4vw;
letter-spacing:2.5px;
}
#nav-bar li{
list-style:none;
}
#nav-bar a{
text-decoration:none;
color: blue;
}
<header id="header">
<div class="logo">
<img id="img-header" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse2.mm.bing.net%2Fth%3Fid%3DOIP.zjBOOZwVgo-4VI476pnY1QHaFk%26pid%3DApi&f=1&ipt=55595a40798b691f4deffe4af60285dc33326fe0932e67b4acb29ea273dcffaa&ipo=images" alt="pikachu face logo">
</div>
<nav id="nav-bar">
<ul>
<li>
<a class="nav-link" href="#About_us">About us</a></li>
<li><a class="nav-link" href="Services">Services</a></li>
<li><a class="nav-link" href="#Contact_us">Contact us</a></li>
</ul>
</nav>
</header>
So what's happening is that the navbar is not getting the complete width to align the nav-bar elements to the right. Well if you give the width:100% and add the justify-content: right to your #nav-bar it should fix the alignment. Please refer the complete code:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: #b6eaf1;
font-family: Cambria, sans-serif;
}
header {
display: flex;
top: 0;
width: 100%;
border: 5px solid blue;
}
.logo img {
width: 17vw;
display: flex;
justify-content: flex-start;
align-items: center;
}
img {
height: 100%;
width: 100%;
}
#nav-bar {
display: flex;
justify-content: right;
width: 100%;
}
#nav-bar ul {
list-style: none;
display: flex;
flex-direction: row;
justify-content: flex-end;
height: 100%;
gap: 4vw;
letter-spacing: 2.5px;
}
#nav-bar li {
list-style: none;
}
#nav-bar a {
text-decoration: none;
color: blue;
}
<header id="header">
<div class="logo">
<img id="img-header" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse2.mm.bing.net%2Fth%3Fid%3DOIP.zjBOOZwVgo-4VI476pnY1QHaFk%26pid%3DApi&f=1&ipt=55595a40798b691f4deffe4af60285dc33326fe0932e67b4acb29ea273dcffaa&ipo=images" alt="pikachu face logo"
/>
</div>
<nav id="nav-bar">
<ul>
<li>
<a class="nav-link" href="#About_us">About us</a>
</li>
<li><a class="nav-link" href="Services">Services</a></li>
<li><a class="nav-link" href="#Contact_us">Contact us</a></li>
</ul>
</nav>
</header>
Below is a drop-down list nested in a drop-down list. the first code snippet works just fine; as I hover over the parent of the first drop-down list it's height transitions and it displays as I intended, as with the subsequent nested drop-down list.
The problem is with the second snippet...
* {
margin: 0;
padding: 0;
}
body {
background-color: hsla(33,25%,75%,1);
box-sizing: border-box;
}
.flex-container {
width: 100%;
}
.flex-container a {
background: lightskyblue;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
height: 25px;
padding: 10px;
text-decoration: none;
transition: background-color 500ms, height 500ms, color 500ms;
}
.flex-container a:hover {
background: cornflowerblue;
color: snow;
}
.flex-container li:hover {
box-shadow: 10px 10px 10px black;
}
.flex-container ul {
list-style: none;
display: flex;
}
.flex-container > ul > li {
width: 100%;
position: relative;
}
ul li ul {
flex-direction: column;
position: absolute;
width: 100%;
left: 50%;
}
ul li li {
width: 100%;
top: 0;
height: 0;
overflow: hidden;
transition-duration: 500ms;
}
li:hover > ul > li {
height: 45px;
}
/*
ul li li:hover {
transform: scale(1.1);
}
*/
<!DOCTYPE html>
<html lang="eng">
<head>
<title>Page 2</title>
<meta charser="utf-8">
<link rel="stylesheet" href="styles/styles2.css">
</head>
<body>
<div class="flex-container">
<ul>
<li>
Home
<ul>
<li>
Two
</li>
<li>
Two
</li>
<li>
Two
<ul>
<li>
two
</li>
<li>
two
</li>
</ul>
</li>
</ul>
</li>
<li>
Home
</li>
<li>
Home
</li>
<li>
Home
</li>
</ul>
</div>
</body>
</html>
Here I make one change at the very bottom of the CSS as I wanted the hover effect to be just a bit more pronounced. I apply a transform scale effect to the dropdown list's li's.
The first drop-down list works just fine, but then the second drop-down list does not.
Can someone please explain what is happening?
* {
margin: 0;
padding: 0;
}
body {
background-color: hsla(33,25%,75%,1);
box-sizing: border-box;
}
.flex-container {
width: 100%;
}
.flex-container a {
background: lightskyblue;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
height: 25px;
padding: 10px;
text-decoration: none;
transition: background-color 500ms, height 500ms, color 500ms;
}
.flex-container a:hover {
background: cornflowerblue;
color: snow;
}
.flex-container li:hover {
box-shadow: 10px 10px 10px black;
}
.flex-container ul {
list-style: none;
display: flex;
}
.flex-container > ul > li {
width: 100%;
position: relative;
}
ul li ul {
flex-direction: column;
position: absolute;
width: 100%;
left: 50%;
}
ul li li {
width: 100%;
top: 0;
height: 0;
overflow: hidden;
transition-duration: 500ms;
}
li:hover > ul > li {
height: 45px;
}
ul li li:hover {
transform: scale(1.1);
}
<!DOCTYPE html>
<html lang="eng">
<head>
<title>Page 2</title>
<meta charser="utf-8">
<link rel="stylesheet" href="styles/styles2.css">
</head>
<body>
<div class="flex-container">
<ul>
<li>
Home
<ul>
<li>
Two
</li>
<li>
Two
</li>
<li>
Two
<ul>
<li>
two
</li>
<li>
two
</li>
</ul>
</li>
</ul>
</li>
<li>
Home
</li>
<li>
Home
</li>
<li>
Home
</li>
</ul>
</div>
</body>
</html>
Fixed.
I don't understand why the problem occurred in the first place, nor do i understand why the fix I found works but it does.
I simply made the overflow property 'visible' in the (ul li li:hover ) and it works.
I had everything working fine, then I was cleaning up css and moved some stuff around. Ilost my horizontal menu bar, it all went vertical:$
Ive been tweeking and searched the site for hours and still no luck. Might be a simple error in my code. I am pretty sure its something in css.
Would prefer not to have to use float....
Thanks for your assistance....
I might have a bit more code than need. this is where is got it
http://www.youtube.com/watch?v=PN1iMaVfzfQ
Website:
http://www.enhancedliving.ca/
CSS:
#menu_Box{ /*MENU BOX CONTAINER*/
width: 890px;
height: 100%;
margin: 0 auto;
padding-left: 10px;
}
#menu_Box ul{ /*MENU BOX STYLE*/
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
color:#263A75;
font-size:24px;
font-weight:normal;
padding:0 0 0 10px;
margin:0;
position:relative;
}
.extraStyle{
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
color:#263A75;
font-size:24px;
font-weight:normal;
padding:0;
margin:0;
}
#menu_Box ul li{
display:inline-block;
}
#menu_Box ul li:hover{
color:#456692;
}
#menu_Box ul li a,visited{
text-align:left;
color:#263A75;
display:block;
padding: 0 0 0 0; /*Padding between titles*/
text-decoration:none;
}
#menu_Box ul li a:hover{
color:#456692;
text-decoration:none;
}
#menu_Box ul li:hover ul{
display:block;
}
/* ############### DROP DOWN MENU BOX ################ */
#menu_Box ul ul{ /*Drop Down Box*/
border: 3px solid rgba(0, 57, 96, .85) ;
display:none;
position:absolute;
background-color: rgba(139, 183, 212, .9);
padding: 3px; /*Padding between list items*/
}
#menu_Box ul ul li{ /*Drop Down Style*/
display: block;
}
#menu_Box ul ul li a,visited{
color:#263A75;
}
#menu_Box ul ul li a:hover{
color:#456692;
}
HTML:
<ul>
<li>Services
<ul>
<li>Psych-K </li>
<li>Food & Environmental Allergy and Sensitivity Testing </li>
<li>Supplement and Nutrition Evaluation </li>
<li>Food Value Testing </li>
</ul>
</li> <p class="extraStyle">::</p>
<li>Sessions </li> <p class="extraStyle">::</p>
<li>Biography </li> <p class="extraStyle">::</p>
<li>Health Topics </li><p class="extraStyle">::</p>
<li>Favorite Products </li><p class="extraStyle">::</p>
<li>Contact </li>
</ul>
Change the
<p class="extraStyle">::</p>
Into
<span class="extraStyle">::</span>
Please help, need to add delay on css menu mouse out. Tried different ways but no success. Is it possible to add some javascript code to existing menu?
Please check the jsFiddle example: http://jsfiddle.net/mZLFz/
<div id="nav">
<ul>
<li class="abt">About Us
<ul>
<li>Our style</li>
<li>Our mission</li>
</ul>
</li>
<li class="col">Collection
<ul>
<li class="col-a">2013
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
<li class="col-b">2014
<ul>
<li>A</li>
</ul>
</li>
</ul>
</li>
<li class="buy">Good to know
<ul>
<li class="buy-a">Men
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</li>
<li class="buy-b">Women
<ul>
<li>A</li>
</ul>
</li>
<li class="buy-c">Kids
<ul>
<li>A</li>
</ul>
</li>
</ul>
</li>
#nav{
height:40px;
overflow:hidden;
list-style:none;
}
#nav ul {list-style:none;}
#nav ul li {text-decoration: none;float:left;}
#nav ul li a {
text-transform:uppercase;
font-size:14px;
color:#bcbec0;
text-decoration: none;
padding:0 20px 3px 20px;
}
#nav ul li:hover > a{border-bottom: 2px solid #afb0bd;color:#383a49;}
/* 1 LEVEL DROP-DOWN MENU */
#nav ul li.abt ul {margin-left:-30px;}
#nav ul li.col ul {margin-left:-100px;}
#nav ul li.buy ul { margin-left: -213px;}
#nav ul li.buy ul li {margin-left: 30px;}
#nav ul li ul { display:none;}
#nav ul li:hover > ul {width:100%;display:block; position:absolute; top:48px;background:#e7e8e9;}
#nav ul li:hover > ul li{ float:left;padding:10px 0 5px 0;list-style:none;}
#nav ul li:hover > ul li a {}
#nav ul li:hover > ul li a:hover {}
/* 2 LEVEL DROP-DOWN MENU */
#nav ul li ul li.col-a ul { margin-left:-50px;top:35px;}
#nav ul li ul li.col-b ul { margin-left:-100px;top:35px;}
#nav ul li ul li.buy-a ul { margin-left:-30px;top:35px;}
#nav ul li ul li.buy-b ul { margin-left:-160px;top:35px;}
#nav ul li ul li.buy-c ul { margin-left:-30px;top:35px;}
#nav ul li > ul li ul { display:none; }
#nav ul li > ul li:hover > ul {width:980px; display:block; position:absolute;background:#f1f1f2;}
#nav ul li > ul li:hover ul li {float:left;padding-top:10px; list-style:none; }
#nav ul li > ul li:hover ul li a {}
#nav ul li > ul li:hover ul li a:hover { }
You can change some :hover to .hover and add some jQuery like this?
$('li').hover(
function(){
var x = this;
setTimeout(
function(){
$(x).addClass('hover')
}, 800
)
},
function(){
$(this).removeClass('hover')
}
)
I am trying to switch out the show and hide functions of jquery for the hoverintent plugin. I want to do this for 2 reasons, number one you can control how long the mouse is over the menu item before the sub item pops up, and number 2 it stops multiple instances from building up. I have been trying since last night to change my code, but I am just not getting this to work...below is my original jquery and html, any help would be greatly appreciated. Thanks ALL!!!
Web Site with Dropdown Menu
http://www.nestudiosonline.com/test.php
Jquery
$(document).ready(function() {
// shows the hidden div in the list
$('#dave').mouseover(function() {
$('#aboutdke').show('200');
});
// hides the hide the div again for that list item
$('#dave').mouseleave(function() {
$('#aboutdke').hide();
}); });
html
<ul id="menu">
<li class="mega"><a class="dkeorg" href="#">DKE.ORG</a></li>
<li class="megamenu" id="dave"><a class="links" href="#">ABOUT DKE</a> <div id="aboutdke">div content </div></li>
<li class="megamenu"><a class="links" href="#">ALUMNI</a></li>
<li class="megamenu"><a class="links" href="#">UNDERGRADUATES</a></li>
<li class="megamenu"><a class="links" href="#">EVENTS</a></li>
<li class="megamenu"><a class="links" href="#">MULTIMEDIA</a></li>
<li class="megamenu"><a class="links" href="#">SHOP DKE</a></li>
</ul>
I did it yay...this is the most simple jquery solution to do a basic drop div with the hoverintent plugin, my html did not have to change at all, ill show my css too....observe
<script type="text/javascript" charset="utf-8">
//<![CDATA[
$(document).ready(function() {
//add hovering class to li's inside of the unordermened with the id menu
function addMega(){
$(this).addClass("hovering");
}
//remove hovering class to li's inside of the unordermened with the id menu
function removeMega(){
$(this).removeClass("hovering");
}
//configuariton for hoverintent plugin, hoveron time, mouse sensitivity, hoveroff time
var megaConfig = {
interval: 300,
sensitivity: 4,
over: addMega,
timeout: 200,
out: removeMega
};
//make list items with the class megamenu have the hoverinter plugin excuted on them
$("li.megamenu").hoverIntent(megaConfig)
});
//]]>
</script>
CSS
ul#menu
{
display:block;
list-style-type:none;
margin:0;
padding:0;
}
ul# menu li
{
display:inline;
position: relative;
}
ul#menu div {
display: none;
}
ul#menu li.mega div {
position: absolute;
}
ul#menu li.hovering div {
display: block;
}
#aboutdke
{
display:block;
color:#FFF;
text-align:left;
font-family:Verdana, Geneva, sans-serif;
font-size:10px;
background-color:#000;
margin:0;
padding-top:10px;
padding-right:10px;
padding-bottom:10px;
padding-left:10px;
border:0px;
width:910px;
height:280px;
float:left;
position:absolute;
z-index:99999;
top:164px;
left:140px;
}
a.links:link
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
a.links:visited
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
/* mouse over link */
a.links:hover
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
background-color:#000;
float:left;
}
/* selected link */
a.links:active
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
background-color:#000;
float:left;
}
a.dkeorg:link
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
a.dkeorg:visited
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
}
/* mouse over link */
a.dkeorg:hover
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
float:left;
}
/* selected link */
a.dkeorg:active
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
float:left;
}