I have been following a tutorial online about creating a sidebar and i have run into an issue. When i hover over one of the menus a sub menu appears. But if i put anything to the right of the menu the sub menu does not appear only when you put the mouse over it. I want the menu to appear over the text to the right of the sidebar
The menu works perfectly when nothing is to the left (e.g. overflow:auto;)
Here is a jfiddle example of the issue
HTML
<nav id="sidebar-menu">
<ul class="parent-sidebar-menu">
<li>Home & Kitchen
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>Electronics
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul></li>
<li>Clothing
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul></li>
<li>Cars & Motorbikes
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>Books
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>Support
<ul>
<li>Contact Us</li>
<li>Forum</li>
<li>Deliveries</li>
<li>T&C</li>
</ul>
</li>
</ul>
</nav>
</div>
<div align="top">
<p>this is just a test</p>
</div>
CSS
p, ul, li, div, nav
{
padding:0;
margin:0;
}
body
{
font-family:Calibri;
}
#sidebar-menu {
overflow: visible;
position:relative;
z-index:2;
}
.parent-sidebar-menu {
background-color: #0c8fff;
min-width:200px;
float:left;
}
#sidebar-menu ul
{
list-style-type:none;
}
#sidebar-menu ul li a
{
padding:10px 15px;
display:block;
color:#fff;
text-decoration:none;
}
#sidebar-menu ul li a:hover
{
background-color:#007ee9;
}
#sidebar-menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#sidebar-menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: -1;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#sidebar-menu ul li > ul li a:hover
{
background-color:#2e2e2e;
}
Does anyone know how to fix this?
Your sub-menu actually is showing up; it's just the background color that doesn't show up. Right now, you have the background color applied the sub-menu's UL. If you instead apply the background-color to the LIs within that UL, it fixes the issue (I think this might be because of the UL's very low z-index?).
Anyway, here's the CSS rule to add:
#sidebar-menu ul li > ul li {
background-color: #333;
}
You can then remove the background-color from #sidebar-menu ul li > ul since it doesn't do anything.
The issue is that you have a z-index of -1 (so behind everything) on the CSS for your rollover.
Changing the Z-index of the #sidebar-menu ul li > ul to 100 and the z-index of the #sidebar-menu to 200 fixes it.
This should be your CSS:
p, ul, li, div, nav
{
padding:0;
margin:0;
}
body
{
font-family:Calibri;
}
#sidebar-menu {
overflow: visible;
position:relative;
z-index:200;
}
.parent-sidebar-menu {
background-color: #0c8fff;
min-width:200px;
float:left;
}
#sidebar-menu ul
{
list-style-type:none;
}
#sidebar-menu ul li a
{
padding:10px 15px;
display:block;
color:#fff;
text-decoration:none;
z-index:100;
}
#sidebar-menu ul li a:hover
{
background-color:#007ee9;
}
#sidebar-menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#sidebar-menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: 1;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#sidebar-menu ul li > ul li a:hover
{
background-color:#2e2e2e;
}
Related
I am creating a demo for my homework.
My navigation is not displaying correctly. I have been trying to fix the problem in many ways but none of them work.
demo
here is my demo
<body>
<div class="container">
<div class="content">
<div id="menu">
<ul class="parent-menu">
<li>
Home & Kitchen
<ul>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Electronics
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Clothing
<ul>
<li>item</li>
<li>item</li>
<
</ul>
</li>
<li>
Cars & Motorbikes
<ul>
<li>item</li>
<li>item</li>
<
</ul>
</li>
<li>
Books
<ul>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Support
<ul>
<li>
Contact Us
</li>
<li>
Forum
</li>
<li>Deliveries</li>
<li>T&C</li>
</ul>
</li>
</ul>
</div>
<!-----------Shorcut Panel Content--------->
<div class="shortcutpanel">
<div class="usergroup">
</div>
</div>
</div>
</body>
Here is my CSS code.
/* Basic Style */
html, body{
height:100%;
}
body {
background-color: grey;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
background-size:cover;
}
/*Global Setting*/
.hover{
float:left;
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
overflow: hidden;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: color, background-color;
transition-property: color, background-color;
}
.hover:active, .hover:hover, .hover:focus{
background-color: rgba(32, 152, 209, 0.5);
}
.container{
height:100%;
width:100%;
}
.content{
position:fixed;
top:10%;
left:0%;
height:90%;
width:100%;
}
/* NAVIGATION*/
p, ul, li, div, nav { padding:0; margin:0; }
#menu {
overflow: hidden;
position:fixed ;
left:0%;
top:20%;
z-index:999; }
.parent-menu {
background-color: #0c8fff;
width:180px; }
#menu ul {
list-style-type:none;
}
#menu ul li a {
padding:10px 15px;
display:block;
color:#fff;
text-decoration:none;
}
#menu ul li a:hover {
background-color:#007ee9;
}
#menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: 999;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul li a:hover {
background-color:#2e2e2e;
}
#menu ul li a:focus + ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
/* Shortcut Panel Content */
.shortcutpanel{
position:relative;
left:10%;
top:5%;
height:90%;
width:30%;
float:left;
margin:0;
padding:0;
background-color:rgba(255,240,240,0.1);
}
Here this Demo,its the navigation effect that i want.
But however in my first demo.When you hover over the navi menu, the 2nd level menu will come out but display incorrectly. I don't know how to solve this.
Thanks for helps guys
If i get your question right.. U can do that by width animation..
And change :focus to :hover + ul
DEMO FIDDLE
#menu ul li:hover > ul {
left: 200px;
width: 200px;
}
#menu ul li > ul {
width: 0px;
}
#menu ul li a:hover + ul {
width: 200px;
-webkit-transition: width 300ms ease-in;
-moz-transition: width 300ms ease-in;
-ms-transition: width 300ms ease-in;
transition: width 300ms ease-in;
}
Hope it helps..
I have a vertical menu and when i add content to the page the added content is coming below the menu.I want to prevent the content from falling over.Expecting help from experts here.
In the given example i want demo in same line as my menu.
p, ul, li, div, nav
{
padding:0;
margin:0;
}
body
{
font-family:Calibri;
}
#menu {
overflow: auto;
position:relative;
z-index:2;
}
.parent-menu
{
background-color: #0c8fff;
width:200px;
}
#menu ul
{
list-style-type:none;
}
#menu ul li a
{
padding:10px 15px;
display:block;
color:#fff;
text-decoration:none;
}
#menu ul li a:hover
{
background-color:#007ee9;
}
#menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: -1;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul li a:hover
{
background-color:#2e2e2e;
}
.content {
padding: 12px 12px 12px 12px;
font-size: 0.8em;
line-height: 1.65em;
border-left: 1px solid #bdc1a3;
border-right: 1px solid #bdc1a3;
background-color:#ffffff
}
#dataDiv{
float: left;border:1px solid #bdc1a3;background-color:#f3f5dc;
}
<div class="content">
<div id="menu" style="overflow:hidden">
<ul class="parent-menu">
<li><a href='#'><span>Menu1</span></a>
<ul>
<li><a href='#'><span>SubMenu1</span></a></li>
<li><a href='#'><span>SubMenu2</span></a></li>
</ul>
</li>
<li><a href='#'><span>LOG OUT</span></a></li>
</ul>
</div>
<div id="dataDiv" style="overflow:hidden">
<table>
<tr>
<td style="background-color: #0C9FFF">
Demo
</td>
</tr>
</table>
</div>
Your menu is in a div, which is a block-level element so it takes up the entire width of it's parent element and will push the following content underneath it.
One way to achieve what you're trying to do is to add float: left to your #menu.
Use the style attribute float.
https://jsfiddle.net/4g5tLekm/7/
Modify <div id="menu" style="overflow:hidden"> to <div id="menu" style="overflow:hidden;float:left">
I'm newbie in html and css and I have to build a dropdown menu. I've found many examples in here.
As I can't use JS, I would like to, whenever in a subpage, have the options be highlighted and keep the box open. So far, I can highlight the options easily but the block keep closing (and don't show up open when open the page).
The code is in here and the idea is to keep the submenu inside Menu 3 open (as if you were in Link 4 page).
Does anyone have any idea on how to solve this? Cheers!
Code:
HTML:
<ul id="nav">
<li> Menu 1</li>
<li>Menu 2
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</li>
<li>Menu 3
<ul>
<li>Link 3</li>
<li><a style="background:#d4d5d8;" href="#">Link 4</a></li>
<li>Link 5</li>
</ul>
</li>
<li>Menu 4</li>
</ul>
CSS:
nav {
border:3px solid #3e4547;
box-shadow:2px 2px 8px #000000;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
#nav, #nav ul {
list-style:none;
padding:0;
width:200px;
}
#nav ul {
position:relative;
z-index:-1;
}
#nav li {
position:relative;
z-index:100;
}
#nav ul li {
margin-top:-23px;
-moz-transition: 0.4s linear 0.4s;
-ms-transition: 0.4s linear 0.4s;
-o-transition: 0.4s linear 0.4s;
-webkit-transition: 0.4s linear 0.4s;
transition: 0.4s linear 0.4s;
}
#nav li a {
background-color:#d4d5d8;
color:#000;
display:block;
font-size:12px;
font-weight:bold;
line-height:28px;
outline:0;
padding-left:15px;
text-decoration:none;
}
#nav li a.sub {
background:#d4d5d8;
}
#nav li a + img {
cursor:pointer;
display:none;
height:28px;
left:0;
position:absolute;
top:0;
width:200px;
}
#nav li a img {
border-width:0px;
height:24px;
line-height:28px;
margin-right:8px;
vertical-align:middle;
width:24px;
}
#nav li a:hover {
background-color:#bcbdc1;
}
#nav ul li a {
background-color:#eee;
border-bottom:1px solid #ccc;
color:#000;
font-size:11px;
line-height:22px;
}
#nav ul li a:hover {
background-color:#ddd;
color:#444;
}
#nav ul li a img {
border-width:0px;
height:16px;
line-height:22px;
margin-right:5px;
vertical-align:middle;
width:16px;
}
#nav a.sub:focus {
background:#bcbdc1;
outline:0;
}
#nav a:focus ~ ul li {
margin-top:0;
-moz-transition: 0.4s linear;
-ms-transition: 0.4s linear;
-o-transition: 0.4s linears;
-webkit-transition: 0.4s linears;
transition: 0.4s linear;
}
#nav a:focus + img, #nav a:active + img {
display:block;
}
#nav a.sub:active {
background:#bcbdc1;
outline:0;
}
#nav a:active ~ ul li {
margin-top:0;
}
#nav ul:hover li {
margin-top:0;
}
#nav a.subactive {
background:#bcbdc1;
outline:0;
}
The key part here seem to be with this class I created but not sure what put inside.
#nav a.subactive {
background:#bcbdc1;
outline:0;
}
Normally I find adding things like
#nav ul ul{
display: block !important;
}
or
div.container {
height: auto !important;
opacity: 1 !important;
}
would work, however it would appear that because focus is lost, it closes. I did have luck with the div.container but it only remained open for a short period longer than normal before closing again. Hopefully this helps if even just a tad.
!important is used to over-ride the inline styles that are applied with js so you can probably get away without using that since you are avoiding js.
I've tried to padding-top on hover element ul#top li a but it fails to excute the code, maybe the inline-block display is bothering the padding to display but I dont know any other display to help him be inline and able him padding-top.
Incase my target is not understandable, I'm trying to padd "a" tag on hover to the top (about 5px padding).
Here is my CSS Code:
ul#top{
list-style: none;
}
ul#top li{
display: inline-block;
padding-right: 30px;
}
ul#top li a{
color: white;
text-decoration: none;
font-family: "Comic Sans MS", cursive, sans-serif;
-webkit-transition: color 0.5s ease-out;
-moz-transition: color 0.5s ease-out;
-o-transition: color 0.5s ease-out;
transition: color 0.5s ease-out;
}
ul#top li a:hover{
padding-top: 10px;
color: green;
}
My HTML:
<div class="header">
<div class="menu">
<ul id="top">
<li>Home</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
</div>
</div>
How to enable padding-top in inline-block display? (The inline-block might not be the problem, but I think it is)
You can add bottom: 10px instead with position: relative. Also add padding-bottom for an issue on hover:
ul#top {
list-style: none;
}
ul#top li {
display: inline-block;
padding-right: 30px;
}
ul#top li a {
color: white;
text-decoration: none;
font-family:"Comic Sans MS", cursive, sans-serif;
-webkit-transition: color 0.5s ease-out;
-moz-transition: color 0.5s ease-out;
-o-transition: color 0.5s ease-out;
transition: color 0.5s ease-out;
}
ul#top li:hover a {
position: relative;
padding-bottom: 10px;/*Add padding bottom*/
color: green;
bottom: 10px;/*Add bottom 10px*/
}
body {
background: red;
}
<div class="header">
<div class="menu">
<ul id="top">
<li>Home
</li>
<li>test
</li>
<li>test
</li>
<li>test
</li>
<li>test
</li>
</ul>
</div>
</div>
So I have a pure css dropdown menu, but I'm having one problem. The dropdown works when you hover over a link, but it's also triggering when you hover over the actual container that contains the dropdown portion. Here's a jsfiddle with the code. http://jsfiddle.net/9BRac/
<div class="nav-con">
<nav role='navigation' id="nav">
<ul>
<li id="linked">Home</li>
<li>About
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
<li>Clients
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
<li>Contact Us
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
</ul>
</nav>
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav {
width: 100%;
height: 60px;
background-color:black;
border-bottom: #ffd600 solid 10px;
margin: 0 auto;
}
nav ul {
position:inheirt;
}
nav ul li {
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
width: 80px;
height:60px;
margin-left:10px;
display:;
float: left;
line-height: 60px;
text-align:center;
list-style:none;
position:inherit;
color: white;
text-decoration:none;
}
nav ul li:hover {
width: 80px;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
height:60px;
margin-left:10px;
background-color:#ffd600;
float: left;
line-height: 60px;
text-align:center;
list-style:none;
position:inherit;
color: white;
text-decoration:none;
}
nav ul li a {
color: white;
text-decoration:none;
}
html {
background-color: #f2f2f2;
}
#dropdown {
width:100%;
height:200px;
opacity: 0.8;
background-color:black;
display:none;
}
.dropdown {
margin-top:10px;
}
.dropdown li {
width: 300px;
background-color: #ffd600;
}
nav ul ul {
opacity: 0;
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in
}
nav ul li:hover > ul {
opacity: 0.8;
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
}
nav ul ul li {
opacity: 1.0 !important;
}
nav ul ul li:hover {
width: 350px !important;
}
Use the following
/* Your dropdown */
nav ul ul {
opacity: 0;
visibility:hidden;
transition: opacity .6s ease-in-out;
-moz-transition: opacity .6s ease-in-out;
-o-transition: opacity .6s ease-in-out;
-webkit-transition: opacity .6s ease-in
}
/* Code to display your dropdown */
nav ul li:hover > ul {
opacity: 0.8;
visibility:visible;
}
For a working example go here http://jsfiddle.net/DanielApt/9BRac/12/
Explanation:
Your .dropdown still exists, it just has an opacity of 0.
Whenever you hover over this “invisible” .dropdown you trigger the hover styling for its parent li, which leads to showing .dropdown again.
The solution: set a visibility of hidden for your .dropdown, and set the visibility to visible only when you hover over the parent li
Also only use the transition on the opacity property, then visibility is changed immediately, but the opacity transitions smoothly.
PS: If you're curious why I'm not using display:none, it is because you can't transition display (source for the solution using visibiliy
Try using visibility:hidden instead of editing just the opacity on hover like this:
http://jsfiddle.net/9BRac/18/
Now you can edit a bit the transitions timing to make it smoother.
As well the transition property could be used on opacity only and not on all properties.