I am trying to make CSS-only dropdowns. I have some CSS that, when a nav item is hovered, its background color changes.
.horiz-nav {
background: linear-gradient(#EEE, #900) no-repeat fixed;
border: none;
outline: none;
}
.horiz-nav ul {
list-style: none;
}
.horiz-nav ul li {
display: inline-block;
padding: 1.2em;
clear: none;
float: left;
margin: 0 0;
background: #000;
width: 10em;
transition: all .5s ease-in;
}
.horiz-nav ul ul {
display: none;
position: absolute;
top: 73px;
height: 0;
transition: all .5s ease-in;
}
.horiz-nav ul ul li {
background: linear-gradient(#000, #F50) no-repeat fixed;
padding: 7px;
margin: 0 3px;
color: #FFF;
}
.horiz-nav ul li:hover {
background: linear-gradient(to bottom, #808080, #80108F);
}
.horiz-nav ul li:hover > ul {
display: block;
height: auto;
}
.horiz-nav ul li:hover > ul li {
display: list-item;
position: relative;
float: none;
left: -62px;
}
<nav class="horiz-nav">
<ul>
<li class="title">Example.com
</li>
<li>About
</li>
<li>Contact
</li>
<li>Programming <span class="caret"></span>
<ul>
<li>HTML</li>
<li>PHP</li>
</ul>
</li>
</ul>
</nav>
With this CSS, the background changes to the new color, but it doesn't fade, with the transition. It does, however fade back to the old color on mouseout. Why is the transition only working on mouseout? And how can I make the background fade by both mouseover and mouseout? FIDDLE
You can't, Gradients don't support transitions
What you can do ?
Add another element under the li with same width and height and position, this element has the gradient background, and play with his opacity when hovering the li.
li .background-holder{
position : absolute;
width : 100%;
height : 100%;
top : 0;
left : 0;
background : linear-gradient(to bottom, #808080, #80108F);
opacity : 0;
transition : all 0.5;
}
li:hover .background-holder{
opacity : 1;
}
JSFiddle : http://jsfiddle.net/qrky8yyp/1/
Related
hello is it possible that when I hover to the parent item the parent item will also slide up making the drop down menu with parent item above it? here is my code but I cant seem to make it work. here is a visual menu that i want http://imgur.com/om9mvdG (the second image)
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
background: #333;
}
.nav ul:before,
.nav ul:after {
content: "";
display: table;
}
.nav ul:after {
clear: both;
}
.nav ul > li {
float: left;
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
}
.nav a:hover {
text-decoration: none;
background: #595959;
}
.nav li ul {
background: #273754;
position: absolute;
left: 0;
bottom: 36px;
z-index: 1;
}
.nav li ul li {
width: 100%;
overflow: hidden;
height: 0;
-webkit-transition: height 200ms ease-in;
-moz-transition: height 200ms ease-in;
-o-transition: height 200ms ease-in;
transition: height 200ms ease-in;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav ul > li:hover ul li {
height: 36px;
}
<ul>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
</ul>
</nav>
Add this css to your already existing code. Is this what you wanted?
http://codepen.io/anon/pen/jbBgdg
li>ul {
display: none;
}
a:hover~ul {
display: block;
}
I am trying to make a sublevel drop down menu. I have successfully gotten the first menu but the second menu sticks out no matter what when you mouse over the first drop down menu. I want it so that the second level only appears when you mouse over the first level. Any help would be greatly appreciated. The following is my html code:
HTML
<nav>
<ul>
<li><span></span> Home </li>
<li>
<span></span> Jwewlry
<ul>
<li>
<span></span> Rings
<ul>
<li>Silver</li>
<li>Copper</li>
<li>Bronze</li>
</ul>
</li>
<li><span></span> Pendants </li>
<li><span></span> Bracelets </li>
<li><span></span> Necklaces </li>
<li><span></span> Other </li>
</ul>
</li>
<li><span></span> Testimonials </li>
<li><span></span> Latest Offers </li>
<li><span></span> News </li>
<li><span></span> Contact Us </li>
</ul>
</nav>
CSS
nav {
/* Repeating background image */
background: url(texture.png);
width: 210px;
margin: 20px;
}
nav ul {
/* Remove bullet points */
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
/* Any child positioned absolutely will be positioned relative to this */
position: relative;
}
nav ul li ul li ul li {
position: block;
}
nav a {
color: #e8e8e8;
padding: 12px 0px;
/* Fill all available horizontal space */
display: block;
/* Remove underline */
text-decoration: none;
/* New CSS3 animations: apply transition to background property, taking 1s to change it */
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
font-family: tahoma;
font-size: 13px;
text-transform: uppercase;
padding-left: 20px;
}
nav a:hover {
/* RGBA background for transparancy: last number(0.05) is the transparency */
background: RGBA(255,255,255,0.05);
color: #fff;
}
nav ul li:hover ul {
/* When list item is hovered, display UL nested within. */
display: block;
}
nav ul ul {
/* Remove element from document flow */
position: absolute;
/* Position relative to its parent <li> */
left: 210px;
top: 0;
border-top: 1px solid #e9e9e9;
display: none;
}
nav ul ul li {
width: 200px;
background: #f1f1f1;
border: 1px solid #e9e9e9;
border-top: 0;
}
nav ul ul li a {
color: #a8a8a8;
font-size: 12px;
text-transform: none;
}
nav ul ul li a:hover {
color: #929292;
}
nav span {
width: 12px;
height: 12px;
background: #fff;
display: inline-block;
float: left;
margin-top: 3px;
margin-right: 20px;
position: relative;
transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-webkit-transition: all 0.5s;
}
nav a:hover span {
background: #7d2c41;
transform: rotate(90deg);
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
/* Horizontal line */
nav span:before {
content: "";
width: 12px;
height: 2px;
background: #3a3b3b;
position: absolute;
left: 0px;
top: 5px;
}
/* Vertical line */
nav span:after {
content: "";
width: 2px;
height: 12px;
background: #3a3b3b;
position: absolute;
left: 5px;
position: top;
}
Simply change the hover selector to this:
nav ul li:hover > ul
This way only the first child ul element is visible.
When i hover over the navmenu it pushes other content down on the webpage. In addition, when you hover over the nav the font is no longer in white. I'm sorry I am new at programming and borrowed some of this code so it may be sloppy. Thanks
Here is my html:
<div class="nav">
<ul id="nav">
<li>Home</li>
<li>Shop Online</li>
<li>Online Rentals
<div>
<ul>
<li>Rent Now</li>
<b>Current Rental Customers</b>
<li>Rental Returns</li>
<li>Rental Repairs</li>
<li>Rental Exchanges</li>
</ul>
</div>
</li>
<li>Lessons
<div>
<ul>
<li>Private Lessons</li>
<li>Meet the Teachers</li>
<li>Request a Lesson</li>
</ul>
</div>
</li>
<li>Performing Arts Center
<div>
<ul>
<li>Musical Theater</li>
<li>Kindermusik</li>
<li>Recording Studio</li>
<li>Group Ensembles</li>
</ul>
</div>
</li>
<li>Repairs</li>
<li>My Account</li>
</ul>
</div>
Here is my css:
/* main menu styles */
#nav,#nav ul {
font-family: verdana;
list-style: none;
margin: 0;
padding: 0;
position: fixed;
}
#nav {
height: 50px;
left: 0;
overflow: hidden;
top: 0;
position: relative;
}
#nav li {
float:left;
position:relative;
z-index:10;
}
#nav li a {
background-repeat: no-repeat;
background-position: center top;
color: #fff;
display: inline;
float: left;
font-size: 14px;
height: 51px;
line-height: 40px;
padding: 0 10px;
position: relative;
text-decoration: none;
z-index: 20;
background-color: #005E20;
}
#nav li:first-child a {
background:url(file:///Macintosh%20HD/Users/davidscott/Downloads/example91/images/bg-menu.png) no-repeat left top;
padding-left:35px;
}
#nav li ul li:first-child a {
background-image:none;
padding-left:10px;
}
#nav li.pad {
background: url(file:///Macintosh%20HD/Users/davidscott/Downloads/example91/images/bg- menu.png) no-repeat right top;
display: inline;
height: 51px;
width: 35px;
}
#nav ul {
background-color: #FFFFFF;
height: auto;
padding: 10px 0;
position: absolute;
top: -115px;
width: 180px;
z-index: 1;
border-radius: 8px; /*some css3*/
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
transition: 0.8s ease-in-out;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-moz-transition: 0.8s ease-in-out;
-o-transition: 0.8s ease-in-out;
-webkit-transition: all 0.8s ease-in-out;
color: #005E20;
}
#nav ul li {
width:180px;
}
#nav ul li a {
background:transparent;
height:20px;
line-height:20px;
width:160px;
}
#nav:hover {
height:200px;
}
#nav li:hover ul {
-moz-transform:translate(0,161px); /*some css3*/
-o-transform:translate(0,161px);
-webkit-transform:translate(0,161px);
}
#nav a:hover,#nav li:hover > a {
color:#99ff33;
}
This changes the height of the nav on hover (pushing the rest of the page down):
#nav:hover {
height:200px;
}
This changes the color to green on hover:
#nav a:hover, #nav li:hover > a {
color:#99ff33;
}
Here's a rudimentary example without those hover definitions:
http://jsfiddle.net/w4uyX/
It's all in your CSS code (which seems a bit unorganized to me).
To deal with the menu pushing other content down, please find the selector #nav:hover where a larger height is set.
Then find the selector #nav a:hover,#nav li:hover > a. There is the setting for the different color, when you hover over the menu.
see my navbar and see the difference
http://codepen.io/leandroruel/pen/yrwKI
I found this method of making one image featuring different social icons on it into different social links by using x and y icons to define the section of the image you want featured in a link.
The issue I'm having is that once I set up the code, the background image isn't showing up. If anyone could offer their insight into why this code isn't working as it shoul, it would be greatly appreciated!
CSS:
aside .social {
margin-top: 40px;
}
.social ul {
list-style-type: none;
margin: 0;
}
.social li {
display: block;
width: 24px;
height: 24px;
margin: 0 4px 6px 0;
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
line-height: 20px;
}
.social li:nth-child(8n+0) {
margin-right: 0;
}
.social li a, .social li a:active, .social li a:visited {
opacity: 0.5;
-moz-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
}
.social li a:hover {
opacity: 1;
}
.social li.facebook a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) 0 0; }
.social li.twitter a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -24px 0; }
.social li.youtube a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -48px 0; }
.social li.instagram a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -72px 0; }
.social li.google a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -96px 0; }
.social li.flickr a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -120px 0; }
.social li.linkedin a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -144px 0; }
HTML:
<h1>Find Us On</h1>
<div class="social">
<ul>
<li class="facebook"></li>
<li class="twitter"></li>
<li class="youtube"></li>
<li class="google"></li>
<li class="instagram"></li>
<li class="flickr"></li>
<li class="linkedin"></li>
</ul>
<div>
I have also created a JSFiddle for your convenience here: http://jsfiddle.net/HRHnY/
The code is rendering the list, it's just the background image isn't displaying...
Your anchors are collapsing to 0x0 because you have no content in them. They don't auto-expand to the size of the parent just because you have a background image. Explicitly give them a width/height like the li and you get http://jsfiddle.net/HRHnY/2/
Relevant CSS for the anchors:
display: block;
width: 24px;
height: 24px;
Alternatively you could set width and height to 100% of the parent instead of explicitly setting it.
Working jsFiddle Demo
The a elements, are inline and the width and height of them,
is calculated by the data within them.
So you must set them explicitly, add this rule to your CSS:
.social a {
display: inline-block;
width: 24px;
height: 24px;
}
TIP
It's better to write background-image only once in general selector:
.social a {
background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png);
}
And just change background-position for each element:
.social li.facebook a {
background-position: 0 0;
}
.social li.twitter a {
background-position: -24px 0;
}
I have a navigation menu for my website:
here is the HTML
<ul id="trans-nav">
<li>About Us
<ul>
<li>Contact Us</li>
<li>Login</li>
</ul>
</li>
</ul>
as you can see it has a dropdown (submenu) under the link but the sub menu is displaying under the page content below the menu.
how can i make it display the sub menu OVER the page content rather than behind?
here is the CSS:
#trans-nav {list-style-type: none; height: 40px; padding: 0; margin: 0; }
#trans-nav { list-style-type: none; height: 40px; padding: 0; margin: 0; }
#trans-nav li { float: left; position: relative; padding: 0; line-height: 40px; }
#trans-nav li:hover { background-position: 0 -40px; }
#trans-nav li a { display: block; padding: 0 15px; color: #666666; text-decoration: none; }
#trans-nav li a:hover { background-color:#F36F25; color: #eeeeee; }
#trans-nav li ul { opacity: 0; position: absolute; left: 0; width: 8em; background: #EEEEEE; list-style-type: none; padding: 0; margin: 0; }
#trans-nav li:hover ul { opacity: 1; }
#trans-nav li ul li { float: none; position: static; height: 0; line-height: 0; background: none; }
#trans-nav li:hover ul li { height: 30px; line-height: 30px; }
#trans-nav li ul li a { background: #EEEEEE; }
#trans-nav li ul li a:hover { background: #666666; color:#EEEEEE; }
#trans-nav li { -webkit-transition: all 0.2s; }
#trans-nav li a { -webkit-transition: all 0.5s; }
#trans-nav li ul { -webkit-transition: all 1s; }
#trans-nav li ul li { -webkit-transition: height 0.5s; }
also a fiddle: http://jsfiddle.net/charliejsford/SAXmG/
You don't appear to be defining any z-index. Without it, elements that appear later in the page will appear on top.
To fix this, I suggest adding position:relative to your list's styles, and then you can also add z-index:1000 or some other suitable number.
Not defining any z-index should not be a problem, and i don't think it's wise to define useless z-index everywhere.
With sample CSS code you post there, your menu should lie on the top of any static element that follow it, because your menu is positioned and the rest of your page is not.
So if you're submenu goes behind the page content, the page content you're talking about must be positioned too, and it may be your true problem.