I have a <ul> of items, who get bigger (with animation) on hover. Now i have made them be on the right side of the screen (using the CSS right:0em for the <li> class), and I have set the position of the <li> on hove to fixed so that only it will move left as it grows, and all the over objects in the will stay to the right. The problem is that as a result of that, when I hover over it, the next item gets "under" it. How can I change that? (maybe is there a way to control only the horizontal position property of the <li> on hover?)
Code:
http://jsfiddle.net/KBprd/2/
Without any code to start it is kind of hard to help. But based on what I could gather, you are wanting all the items to stay flush against the right side of the menu; only the "hovered" element is moved away from the right-side of the container. I've slapped together an example of how to do this. If this is not what you are looking for, provide some more code or detail in comments and we can go from there...
Here is the updated Fiddle
CSS:
.navigation{
position:fixed;
z-index:1;
top:3em;
right:0em;
}
.navigation li.slide{
color:#000000;
display:block;
padding: 0 10px;
line-height:30px;
margin-bottom:2px;
font-weight:light;
background:#00C9FF;
-webkit-transition: all .2s ease-in-out;
text-align:right;
width:53px;
float:right;
}
.navigation li:hover,.active{
font-size:25px;
cursor:pointer;
width:100px!important;
background:#5C0CE8;
}
.navigationClear {
clear:both;
height:1px;
margin-bottom:-1px;
}
HTML:
<ul class="navigation">
<li data-slide="1" class="slide">Slide 1</li>
<li class="navigationClear"></li>
<li data-slide="2" class="slide">Slide 2</li>
<li class="navigationClear"></li>
<li data-slide="3" class="slide">Slide 3</li>
<li class="navigationClear"></li>
<li data-slide="4" class="slide">Slide 4</li>
<li class="navigationClear"></li>
</ul>
The reason that your hovered element hides the element below is because you have given "position:fixed" to the hovered element. I fixed your problem by giving the ul element a width so that the li elements wont line up. I also removed the fixed position of the hovered element. and then right floated the li. This way you also dont need to put "clearNavigation" after each element.
Here's your fiddle code.
<ul class="navigation">
<li data-slide="1">Slide 1</li>
<li data-slide="2">Slide 2</li>
<li data-slide="3">Slide 3</li>
<li data-slide="4">Slide 4</li>
.navigation{
position:fixed;
z-index:1;
top:3em;
right:0em;
width:53px;
}
.navigation li{
color:#000000;
display:block;
padding: 0 10px;
line-height:30px;
margin-bottom:2px;
font-weight:light;
background:#00C9FF;
-webkit-transition: all .2s ease-in-out;
text-align:right;
width:53px;
position:relative;
right:0em;
float:right;
}
.navigation li:hover,.active{
font-size:25px;
cursor:pointer;
width:100px!important;
background:#5C0CE8;
right:0em;
}
Related
I using a mobile menu for my website which is dropping down from the top to the bottom. Is their a way to get it open from the left, like the sidebar does? I'm not that familiar with css animation and I tried transform: rotate(90deg); but without any effects.
The mobile menu is visible here https://www.amaoni.de
it can be easily done by using ul,li tags
ul,li{
list-style:none;
padding:0px;
margin:0px;
}
#yourMenu{
border:1px solid #000;
height:200px;
width:30%;
}
#yourMenu>li{
width:100%;
padding:5px;
background-color:blue;
box-sizing:border-box;
color:#fff;
}
#yourMenu>li:hover{
cursor:pointer;
background-color:red;
}
<ul id="yourMenu">
<li>menu 1</li>
<li>menu 2</li>
<li>menu 3</li>
</ul>
I'm trying to style a popup-menu that shows a submenu on hover, popping out to the right of the hovered item.
My main items are split into two columns using column-count, and this is where the misery begins.
In Firefox, everything behaves as expected: the submenu pops out where the hovered item is. In Chrome, the submenu pops up relative to the leftmost column.
The four cases (hovered items 3 and 9, Firefox and Chrome) are shown in the attached screen. Try the demo both in Firefox and Chrome to see what I mean.
Is there a neat solution for this? I tried column-span, but that doesn't work. I cannot make the item's li relative because I want the popup to fill the complete height.
ul.first {
border:1px solid #888;
position:relative;
display:inline-block;
margin:5px;
padding:0;
column-count:2;
-moz-column-count:2;
-webkit-column-count:2;
column-rule:1px solid #888;
-moz-column-rule:1px solid #888;
-webkit-column-rule:1px solid #888;
background-color:#eee;
}
ul.first li {
list-style:none;
display:block;
width:200px;
background-color:#eee;
margin:2px;
padding:5px;
}
ul.first li:hover {
background-color:#ddd;
}
ul.first > li.hassub > ul {
display:none;
position:absolute;
margin-left:100px;
top:0;
bottom:0;
background-color:#ddd;
padding:0 5px;
}
ul.first > li.hassub:hover > ul {
display:inline-block;
}
ul.first > li.hassub > ul > li {
background-color:#ddd;
}
ul.first > li.hassub > ul > li:hover {
background-color:#eeffee;
}
<ul class="first">
<li>Item 1</li>
<li>Item 2</li>
<li class="hassub">Item 3
<ul>
<li>Subitem 3-1</li>
<li>Subitem 3-2</li>
<li>Subitem 3-3</li>
<li>Subitem 3-4</li>
</ul>
</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li class="hassub">Item 9
<ul>
<li>Subitem 9-1</li>
<li>Subitem 9-2</li>
<li>Subitem 9-3</li>
<li>Subitem 9-4</li>
</ul>
</li>
<li>Item 10</li>
</ul>
http://jsfiddle.net/cfckw5jz/6/
There are many solutions:
Solution 1: A quick solution is to Give the sub-menu inside the right column different class (hassub2), and give it different margin-left
.hassup2{
left: 390px;
}
Solution 2: A smarter solution is to give all sub-menus inside li's above 5 a different margin, this can be achieved by using nth-child:
ul.first > li:nth-child(n+5) > ul{
left: 390px;
}
n + 5 = any element above 5 (in that case all li's above 5)
Solution 3: You can also separate it into 2 UL's and float them left (or use display: inline-block), and assign position relative to the UL's to be the reference point for the sub-menu:
li{ list-style: none; }
ul.left,
ul.right{
float: left;
width: 200px;
position: relative;
}
.right li,
.left li{
float: left;
width: 100%;
background-color: #eee;
margin: 2px;
padding: 5px;
}
.right li ul,
.left li ul{
display: none;
position: absolute;
left: 200px;
top:0;
height:100%;
}
.right li ul li,
.left li ul li{
width: 100%;
padding: 5px;
margin: 2px;
}
.right li:hover ul,
.left li:hover ul{
display: block;
}
Tip: use Left instead of margin-left for a consistent design, using left will always make the element 200px away from left side, it will not depend or get effected on any element placed before it, like what margins behave.
Tip: Absolute positioned element will look for the first father with a defined position and make it its reference point. So to make an absolute div refer to the direct father div, the father must be given position (relative, fixed, or absolute).
Today I realized that this issue was fixed in the latest Chrome release 55 and now Chrome behaves as the other modern browsers.
So, no need to make modifications to css nor html. Yay!
I have a very simple vertical bar chart made solely by css:
it is made of list items:
<ul class="graph">
<li style="height:50%; ">25</li>
<li style="height:80%;">40</li>
<li style="height:20%;">10</li>
<li style="height:40%;">20</li>
<li style="height:10%;">5</li>
</ul>
with the help of css:
.graph {
width:100%;
height:250px;
position:relative;
background-color:gray;
}
.graph li{
bottom:0;
width:5%;
text-align:center;
background-color:#9FC;
list-style:none;
position:relative;
border-style:solid;
border-width:1px;
display:inline-block;}
the problem is that the bars are upside-down. How could I make them right way up?
thanks
Your li elements should be positioned absolute. However you need to set margin for each element. I used it by adding left property:
<ul class="graph">
<li style="height:50%; ">25</li>
<li style="height:80%;left:20%">40</li>
<li style="height:20%;left:40%">10</li>
<li style="height:40%;left:60%">20</li>
<li style="height:10%;left:80%">5</li>
</ul>
And in CSS i modified this:
.graph li {
position:absolute;
}
DEMO
Morning again...,
Sorry to bother everyone but I need more help... I haven't done any real coding in ages so here goes...
I'm trying to make a horizontal navigation menu, here's my html
<nav>
<ul id="navmenu">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
<ul>
<nav>
now I have the following CSS
/* menu */
ul#navmenu{
border-top:1px solid #FFF;
background:#e60000;
list-style: none;
margin: 0;
padding: 0;
padding-left:30px;
}
ul#navmenu li{
display:inline;
}
ul#navmenu li a{
color:#fff;
text-decoration:none;
/*
padding-left:15px;
padding-right:15px;
*/
padding:15px 15px 15px 15px;
}
ul#navmenu li a.selected{
color:#e60000;
text-decoration:none;
/*
padding-left:15px;
padding-right:15px;
*/
padding:15px 15px 15px 15px;
background:#fff;
}
I want the links to sit in the center of the Li and look something like this:
However the containing UL doesn't seem to contain the LIs, they bleed out of the container. I've played around with overflow and line heights but nothing seems to work... here's a worst case scenario...
does any one have any ideas?
give display:block to your <a> because <a> in an inline element so, inline element not take vertical margin, vertical padding, width & height
Check this http://jsfiddle.net/T8eNe/2/
but first close your UL & NAV
For starters, I would close the <ul> and <nav> tags correctly, then check to make sure that the parent containers are floated left.
Give inline-block to your anchor
ul li a { display: inline-block; }
I have a drop down menu (#dropDownMenu) which appears when the "#headerNav" of my website is hovered over. It works properly if I position the #dropDownMenu (originally hidden with display:none until link is hovered over) slightly over the #headerNav div.
This stops the slight flickering that is caused if the cursor isn't moved over fast enough to the drop down menu when it appears. By slightly overlapping #dropDownMenu over #headerNav this makes it seem like the #headerNav is still being hovered over when cursor is actually in the #dropDownMenu.
Anyway I now want to hide the overlapping part of #dropDownMenu behind header or #headerContent so everything looks neater and so the drop down menu actually looks like it's appearing beneath the #headerNav.
I've tried different z-index settings and none seem to work which is quite annoying. When I set the z-index of #headerNav:hover #dropDownMenu to -1 it is hidden behind all content as expected.
If I set z-index of header or #headerContent to a number higher than "#headerNav:hover #dropDownMenu" then hover over #headerNav there is no difference. I can still see #dropDownMenu overlapping.
CSS:
header {
position:fixed;
top:0;
right:0;
left:0;
height: 40px;
z-index:20;
}
#headerContent {
background-color: $main-background-color;
width: $site-width;
margin:0px auto 0px auto;
height:40px;
}
#headerNav {
float:right;
height:37px;
width:auto;
margin-top:1px;
background-color:#464646;
color:#cccccc;
}
#headerNav:hover {
background-color:#626262;
cursor:pointer;
color: white;
}
#headerNav:hover #dropDownMenu {
position:absolute;
background-color:white;
border:1px solid gray;
top:35px;
right:-39px;
height:300px;
width:200px;
font-weight:bold;
color:gray;
display:block !important;
z-index:1;
}
ul li {
float:right;
}
#photoThumbnail img {
height:28px;
width:31px;
padding-top:5px;
padding-right:8px;
-moz-border-radius: 1px 12px 1px 12px;
border-radius: 1px 12px 1px 12px;
}
#currentUser {
position:relative;
padding-top:12px;
padding-left:12px;
padding-right:6px;
}
#siteNavigation {
display:none;
}
HTML
<header>
<div id='headerContent'>
<div id='LogoHolder'>
</div>
<nav id='headerNav'>
<ul>
<li id='photoThumbnail'></li>
<li id='currentUser'>
<ul id='dropDownMenu'>
<li>link1</li>
<li>link2</li>
<li>link3</li>
<li>link4</li>
<li>link5</li>
<li>link6</li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
Examples and corrections will be greatly appreciated.
Kind regards
If your z-index setting is being ignored you might need to add position property, set it to relative or whatever it needs to be. I'm pretty sure z-index is ignored if position property is not set.
I think you'll find that you are trying to hack your way around a fundamental markup issue. THe usual way to do ul based drop downs is this
<ul id='headerNav'>
<li>Menu Title
<ul class='dropDownMenu>
<li>link1</li>
<li>link2</li>
</ul>
</li>
</ul>
This way you set the hover action on #headerNav li:hover and your drop down is a child of your hover element and the menu will stay open (and not flicker) when you move your mouse over the .dropDownMenu as it is also being hovered. You're close.. you just need to wrap your html a bit better and adjust your css to hover on the li and show and hide the "li ul.dropDownMenu"
This should get rid of the need for your overlap - and fix your problem.