I'm concluding a design and I'm facing an issue which I'm not familiar with. I'm trying to make a menu expand from hidden to visible over 2 seconds on hover using a transition: height CSS element.
The issue is that the ul is obeying the transition and appearing visible within 2s, however the lis are completely ignoring the transition effect and instantly expanding on hover.
CSS syntax below:
#main_navbar_container{
margin-bottom:0;
background:white;
}
.navbar-collapse {
text-align:center;
}
#menu_container{
width:80%;
float:right;
display:block;
}
#primary_menu{
display:block;
float:left;
width:100%;
}
#primary_menu ul{
list-style: none;
margin: 0;
padding-left: 0;
}
#primary_menu a,
#primary_menu a:visited,
#primary_menu a:link{
color:#ea474b;
font-weight: 600;
display: block;
text-decoration: none;
padding: 15px 20px;
margin:auto;
}
#primary_menu a:hover{
color:#F9690E;
}
#primary_menu li{
float:left;
position:relative;
margin:0
}
#primary_menu ul ul {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
border-radius: 4px;
border: 1px solid #dadada;
background: #fff;
color: #8c9398;
float: right;
position: absolute;
top: 3.5em;
right: -999em;
z-index: 99999;
text-align: center
}
#primary_menu ul li:hover > ul {
right: 50%;
margin-right: -100%;
width: 200px;
}
.sub-menu li{
margin:0 15px !important;
}
#primary_menu ul li ul a{
color:#ea474b;
}
#primary_menu ul li ul:hover a{
color:#ea474b;
}
#primary_menu ul li ul li:hover a{
color:#F9690E;
}
#media (max-width: 1200px){
#main_navbar_container .container, #menu_container { width: 100%;}
#menu_container .navbar-collapse { padding: 0;}
#primary_menu{
width:100%;
margin:0;
}
#primary_menu li{
width:100%;
margin:5px 0 0 0;
}
#primary_menu ul li ul {
border-radius: 0 !important;
border-color: transparent !important;
display:hidden;
height:100px;
-webkit-transition: height 2s; /* Safari */
transition: height 2s;
}
#primary_menu ul li:hover{
background:none;
}
#primary_menu ul li:hover a{
font-color:black;
/*\color:rgb(207,0,15);*/
}
#primary_menu ul li:hover ul{
position:initial;
display:block;
background-color:rgb(238,238,238);
width:100%;
padding:0;
margin:0;
height:400px;
}
#primary_menu ul li:hover li:first-of-type{
border-top:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover li:last-of-type{
border-bottom:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover a:link,
#primary_menu ul li:hover a:visited{
color:#ea474b;
}
#menu-home-screen-menu{
margin-left:0;
}
}
Here is a fiddle: http://jsfiddle.net/x15jw967/
A few things help here. First, transition max-height instead of height to allow variation:
#primary_menu ul li ul {
...
max-height:0;
-webkit-transition: max-height 2s;
transition: max-height 2s;
}
#primary_menu ul li:hover ul {
...
max-height: 400px;
}
Then, set overflow to hidden so the outer content doesn't show:
#primary_menu ul li ul {
...
overflow: hidden;
}
Demo
Here's a simplified demo in which the close transition works also. You can add your styling back in and see what breaks it.
Related
I ran into a problem which I need to solve to present the Website.
The border when I hover my menu isn't moving upwards, only my font moves up a bit.
.srt-menu li a {
transition: 0.3s ease;
background: #3fa46a;
color: red;
font-size: 20px;
text-decoration: none;
padding: 0px 0;
margin: 0 0px;
}
.srt-menu li a:hover{
transition: 0.3s ease;
background: transparent;
color: #1aa8a4;
text-decoration: none;
border-top: 1px solid red;
border-bottom: 4px solid #3fa46a;
padding: 0px 0;
margin: 0 0px;
}
.srt-menu li li a {
background:#e8e8e8;
padding-left:40px;
}
.srt-menu li li li a {
background:#efefef;
padding-left:80px;
}
/*SECONDARY MENU*/
#secondary-navigation{
margin-bottom:60px;
}
``#secondary-navigation ul{
margin:0;
padding:0;
}
#secondary-navigation ul li a{
background:#E6E6E6;
display:block;
margin:5px 0;
padding:10px;
text-decoration:none;
}
#secondary-navigation ul li a:hover,
#secondary-navigation ul li.current a{
transition: 0.3s ease;
background: red;
color: #ffffff;
text-decoration: none;
border-top: 0px solid transparent;
border-bottom: 4px solid #3fa46a;
padding: 24px 0;
}
/*SPACE GRID ELEMENTS VERTICALLY, SINCE THEY ARE ONE UNDER ANOTHER SO FAR*/
.grid_1,
.grid_2,
.grid_3,
.grid_4,
.grid_5,
.grid_6,
.grid_7,
.grid_8,
.grid_9,
.grid_10,
.grid_11,
.grid_12 {
margin-bottom:40px;
/*positioning and padding*/
position: relative;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
}
/*FOOTER*/
footer{
clear:both;
font-size:80%;
padding:20px 0;
}
footer ul{
margin:0;
padding:0;
}
/*colors and backgrounds*/
body{
background:#fff;
}
h1, h2, h3, h4, h5, h6{
color:#333;
}
footer{
background:#333;
color:#ccc;
}
footer h1, footer h2, footer h3, footer h4{
color:#CCC;
margin-bottom:10px;
}
footer ul{
margin:0 0 0 8%;
}
a.buttonlink{
background:#0099ff;
border-radius:7px;
color:#fff;
display:block;
float:left;
margin:10px 15px 10px 0;
padding:10px;
text-decoration:none;
}
a.buttonlink:hover{
background:#8dbc01;
}
.greenelement{
background:#5ec79e;
color:#fff;
}
.violetelement{
background:#887dc2;
color:#fff;
}
/* Contain floats*/
.clearfix:before,
.clearfix:after,
.row:before,
.row:after {
content: " ";
display: table;
}
.clearfix:after,
.container:after,
.row:after{
clear: both;
}
aside {
float:right;
width:30%;
}
/*** MAIN MENU - ESSENTIAL STYLES ***/
.menu-toggle{display:none;}
#menu-main-navigation{display:block;}
.srt-menu, .srt-menu * {
margin: 0;
padding: 0;
list-style: none;
}
.srt-menu ul {
position: absolute;
display:none;
width: 12em; /* left offset of submenus need to match (see below) */
}
.srt-menu ul li {
width: 100%;
}
.srt-menu li:hover {
visibility: inherit; /* fixes IE7 'sticky bug' */
}
.srt-menu li {
float: left;
position: relative;
margin-left:1px;
}
.srt-menu li li {
margin-left:0px;
}
.srt-menu a {
display: block;
position: relative;
}
.srt-menu li:hover ul,
.srt-menu li.sfHover ul {
display:block;
left: 0;
top: 45px; /* match top ul list item height */
z-index: 99;
-webkit-box-shadow: 2px 3px 2px 0px rgba(00, 00, 00, .3);
box-shadow: 2px 3px 2px 0px rgba(00, 00, 00, .3);
}
ul.srt-menu li:hover li ul,
ul.srt-menu li.sfHover li ul {
top: -999em;
}
ul.srt-menu li li:hover ul,
ul.srt-menu li li.sfHover ul {
left: 12em; /* match ul width */
top: 0;
}
ul.srt-menu li li:hover li ul,
ul.srt-menu li li.sfHover li ul {
top: -999em;
}
ul.srt-menu li li li:hover ul,
ul.srt-menu li li li.sfHover ul {
left: 10em; /* match ul width */
top: 0;
}
/*** DEMO1 SKIN ***/
#topnav, .srt-menu {
float:right;
margin: .35em 0 0 0;
}
.srt-menu a {
text-decoration:none;
}
.srt-menu li a {
background:#fff;
margin:0;
padding:10px 20px;
height:45px;
}
.srt-menu a, .srt-menu a:visited { /* visited pseudo selector so IE6 applies text colour*/
color: #0099ff;
}
.srt-menu li li a {
border-top: 1px solid rgba(255,255,255,.2);
background: #333; /*fallback for old IE*/
background:rgba(0,0,0,.6);
color: #fff;
padding-left:20px;
height:auto;
}
.srt-menu li li a:visited{color:#fff;}
.srt-menu li li li a,
.srt-menu li.current * li a{
padding-left:20px;
background:rgba(0,0,0,.6);
}
.srt-menu li:hover > a,
transition: 0.3s ease;
background: transparent;
color: #1aa8a4;
text-decoration: none;
border-top: 0px solid transparent;
border-bottom: 4px solid #3fa46a;
padding: 24px 0;
}
.srt-menu li li:hover > a{
color:green;
background:#0099ff;
}
<nav id="topnav" role="navigation">
<div class="menu-toggle">Menu</div>
<ul class="srt-menu" id="menu-main-navigation"><li class="current">Start<ul><li>Test</li></ul></li><li>Kontakt</li><li>Öffnungszeiten</li><li>Anfahrt</li><li>testststst</li></ul> </nav><!-- #topnav -->
<!-- main content area -->
<div class="wrapper" id="main">
Take a look on my website where you can see the problem in action.
How can I create the menu look like here?
I want the bottom border to move in when I hover on it, and move out when I leave the "button".
The example you are trying to copy is not structured the same way your site is.
On :hover, You can simply add a box-shadow for the bottom:
box-shadow: 0 4px 2px -2px gray;
I'm not sure if this can be done that way it was built but I'd like to add a transition effect to my dropdown. Anything that would make it seem less choppy. SLide, fade etc. Codepen below.
<div id="nav-wrap">
<ul>
<li id="link-one" class="orange">
<span>Test</span>
<div class="subnav">
<ul>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div><!-- /.subnav -->
</li>
<li class="red"><span>Test</span></li>
<li class="pink"><span>Test</span></li>
<li class="purple"><span>Test</span></li>
<li class="blue"><span>Test</span></li>
<li class="green"><span>Test</span></li>
<li class="yellow-facebook"><span></span></li>
</ul>
</div> <!-- nav-wrap -->
#nav-wrap .doubleLine {
display: table-cell;
line-height: 1.2em;
width:65.275%;
}
#nav-wrap {
width:100%;
height:100px;
font-weight:500;
padding: 0;
left:0;
font-family: 'Raleway', Arial, sans-serif;
z-index:100;
float:left;
}
#nav-wrap ul {
list-style-type: none;
margin: 0;
padding:0;
text-transform: uppercase;
}
#nav-wrap ul li {
width:14.275%; /* ~(100/7) */
display:block;
float:left;
text-align:center;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#nav-wrap ul li + li {
border-left: 1px #fff solid !important;
}
#nav-wrap ul li a {
width:100%;
display: block;
height: 100%;
position: relative;
color:#FFFFFF !important;
text-decoration:none;
}
#nav-wrap ul li span {
display: inline-block;
vertical-align: middle;
height: 100px;
font-size:1.45em;
text-align: center;
padding: 0 5% 0 5%; /* was 0 20px */
line-height: 100px;
}
#nav-wrap ul li.yellow-facebook {
width:14.275%;
}
#nav-wrap ul li.yellow-facebook a {
background-size:130px 26px; /* > 25px */
}
li .subnav {
display: none;
/*position: absolute; */
clear: both;
margin-left: 0;
font-size:0.9em;
}
.subnav ul {
margin-left: 0;
float:left;
padding:0;
width:100%;
}
.subnav ul li {
margin: 0 0 0 0;
width:100% !important;
height:23px;
float:none !important;
}
.subnav ul li a {
padding: 10px 0 3px 0;
/*background-image: url(../images/submenu-background-divider.png);
background-repeat:no-repeat;
background-position:left;*/
}
#nav-wrap .subnav ul li + li {
border-left: none !important;
}
.subnav {
width:100%;
padding: 0;
margin: 0.05% 0 0 0;
border-top:#FFF 1px solid;
}
.subnav ul li a:link, a:active, a:visited {
text-decoration:none;
}
.subnav ul li a:hover {
color:#000;
text-decoration:none;
}
li:hover > .subnav {display:inline-block; left:0;}
#nav-wrap ul li.orange a {
background-color:#f37028;
}
#nav-wrap ul li.orange a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.red a {
background-color:#ed1b24;
}
#nav-wrap ul li.red a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.pink a {
background-color:#e54198;
}
#nav-wrap ul li.pink a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.purple a {
background-color:#6b439c;
}
#nav-wrap ul li.purple a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.blue a {
background-color:#0193cf;
}
#nav-wrap ul li.blue a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.green a {
background-color:#80c02c;
}
#nav-wrap ul li.green a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.yellow-facebook a {
background-color:#fff300;
background-image:url(../images/social-media/facebook-text.png);
background-repeat:no-repeat;
background-position:center;
}
#nav-wrap ul li.yellow-facebook a:hover {
color: #231f20;
background-image:url(../images/social-media/facebook-text_over.png);
}
http://codepen.io/Compton/pen/jLGyo/
You can try a CSS3 transition, only you would have to use opacity instead of display none.
add this
li:hover > .subnav {
display:inline-block;
left:0;
-webkit-transition: all 0.4s ease-in;
-moz-transition: all 0.4s ease-in;
-o-transition: all 0.4s ease-in;
transition: all 0.4s ease-in;
opacity:1.0;
}
and change the display none to this:
li .subnav {
opacity:0;
/*position: absolute; */
clear: both;
margin-left: 0;
font-size:0.9em;
}
Jquery can do some sliding if you'd rather, but this is a little simpler to set up, you can also adjust the height to make it slide down if youd rather that instead of a fade in.
Put this to the animated element CSS:
transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
It basically fools browser that the transition or animation is 3D and enables GPU acceleration and disables two-sided planes in webkit based browsers.
I have a menu bar that has three items with drop down menus. When I hover my mouse over the menu bar itself, the drop down menu shows up, but when I move the mouse away to hover over something in the actual drop down menu, it disappears. I assume I'm missing something in my css code, but I'm not sure what. Here's what I have:
body {
background: url(background.jpg);
font-family:Georgia;
margin:10;
padding:10;
}
.main {
width:1000px;
margin:0 auto;
background: #000;
color:#fff;
}
.main > div {
height:200px;
margin:10px;
}
div.bottom {
height:0;
clear:both;
margin:0;
}
.main .head {
height:100px;
color:#fff;
line-height: 100px;
}
h1 {
font-size: 30px;
font-weight: bold;
margin:0;
}
h5 {
color:#000;
}
.main .page {
min-height:500px;
height:auto;
}
.main .foot {
height:70px;
text-align: center;
line-height: 70px;
}
.span_1 {
width:800px;
}
.span_2 {
width:990px;
}
div.menu {
height:50px;
line-height: 50px;
background:#000;
color:#fff;
}
.menu a:link,
.menu a:visited {
color:#000;
text-decoration: none;
padding:0 10px;
}
.menu ul,
.menu li,
.menu h5,
.menu .mega-drop {
list-style:none;
margin: 0;
padding: 10;
background:#fff;
}
.menu li {
position: relative;
}
.menu > ul > li {
float:left;
border-right:solid 1px;
}
.menu > ul > li > ul {
position: absolute;
left:0;
top:60px;
width:400px;
z-index:1;
display:none;
}
.menu > ul > li > .mega-drop {
position: absolute;
left:0;
top:60px;
z-index:1;
width:400px;
display:none;
}
.menu > ul > li > .mega-drop > .mega-drop-column {
float:left;
width:200px;
}
.menu > ul > li > ul > li > ul {
position: absolute;
left:400px;
top:0;
width:400px;
z-index:1;
display:none;
}
.menu li:hover {
background: #3f0;
}
.menu li:hover > ul,
.menu li:hover > .mega-drop {
display: block;
}
you have to do something like this
<div id="menubar"> <- here is your hover to show the menu
<div id="navpoint1">...</div>
<div id="navpoint2">...</div>
<div id="navpoint3">...</div>
...
</div>
now you are "the whole time" hover 'menubar' and the dropdown will not dissappear
This happened to me and tried several methods. I altered the following code and worked a charm! It was strange because it only happened on the index page!!
Was this...
#nav li ul {
width:100%;
margin:0;
padding:0;
display: none;
position: absolute;
top: 100%;
background-color: #39F;
background: rgba(51, 153, 255, .9);
}
Changed to...
#nav li ul {
width:100%;
margin:0;
padding-top:.2em;
display: none;
position: absolute;
top: 100%;
background-color: #39F;
background: rgba(51, 153, 255, .9);
z-index:99999;
}
I have this CSS code for a horizontal menu:
.vertical-nav {
height:auto;
list-style:none;
width: 100%; /******* MODIFIED ********/
margin-top:0;
margin-bottom:35px;
margin-left:0;
}
.vertical-nav li {
height: 25px;
margin: 0;
padding: 5px 0;
background-color: #666;
border: none;
text-align: center;
display: inline-block;
float: left;
width: 100px; /******* MODIFIED ********/
}
.vertical-nav li:hover {
background-color:#f36f25;
color:#FFFFFF;
}
.vertical-nav li a {
font-family:Calibri, Arial;
font-size:18px;
font-weight:bold;
color:#ffffff;
text-decoration:none;
}
.vertical-nav li.current {
background-color:#F36F25;
}
.vertical-nav li.current a {
color:#FFFFFF;
}
vertical-nav ul li ul {
display:none;
list-style-type:none;
width:125px;
padding:0px;
margin-top:3px;
margin-left:-5px;
}
vertical-nav ul li:hover ul {
display:block;
}
vertical-nav ul li:hover ul li {
background-color:#555555;
width:125px;
height:30px;
display:inline-block;
}
vertical-nav ul li ul li:hover {
background-color:#333333;
}
vertical-nav ul li ul li a {
color:#FFF;
text-decoration:underline;
}
vertical-nav ul li ul li a:hover {
text-decoration:none;
}
.vertical-nav li ul {
display: none;
margin-top: 10px;
padding: 0;
}
.vertical-nav li:hover ul {
display: block;
}
.vertical-nav li:hover .sub-menu
{
display: table;
}
.sub-menu li
{
width: 100%;
min-width: 180px;
white-space: nowrap;
display:table-row;
z-index:1;
position:relative;
}
.sub-menu li a
{
display:inline-block;
padding: 0 10px;
}
but it has a margin on the left that i cannot work out how to remove.
i have tried doing margin:0 and also margin:-10px etc... but it wont go.
here is a jsFiddle: http://jsfiddle.net/QSEGR/
Actually it isn't margin.
Web browsers apply a padding-left on HTML list elements such as <ul> (Google Chrome set -webkit-padding-start: 40px;).
You could override the user agent stylesheet by setting padding: 0; on <ul> element:
.vertical-nav {
padding: 0;
}
Here is the JSFiddle Demo
Note: There's also a margin: 8px; applied on <body> element by web browsers, you could reset the margin by:
body {
margin: 0;
}
What is the best practice?
Different browsers may have different behavior. they apply several CSS declaration on HTML elements by default. they adds margin, padding, text-decoration and so on.
To get rid of this, most web developers use some CSS declarations called CSS Reset to override the browser's default stylesheet, as a start point.
Take a look at Legendary Eric Meyer's CSS Reset.
add padding: 0; to the unordered list.
I was trying to make menu at the top that drops down another menu it works but it overlap the menu at the top I tried absolute value but the submenu it gone I think absolute wont work and i tried relative it didnt work as well.
what is the best way to fix this?
http://jsfiddle.net/TBEnf/ Here is the Jfiddle demo
Here is my code
<style>
.midbox {
margin:0px auto;
width:900px;
height:1000px;
background:#c0d8d8;
border-radius:10px;
box-shadow: 10px 10px 10px #969696;
}
.headerprofile {
width:900px;
height:30px;
background-color:skyblue;
border-top-left-radius:10px;
border-top-right-radius:10px;
box-shadow:0 1px -2px #70badb
}
.headerprofile .ULlist ul li:hover > ul{
display:block;
}
.headerprofile .ULlist ul ul li a {
padding: 15px;
position:relative;
}
.headerprofile .ULlist ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
.headerprofile .ULlist ul ul {
display: none;
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
.headerprofile .ULlist ul {
position:relative;
list-style:none;
padding:0 10px;
}
.headerprofile .ULlist ul li {
float:left;
}
.headerprofile .ULlist ul li a{
display: block; padding: 6px 10px;
color: #757575; text-decoration: none;
}
Just set position:relative on the parent li instead of the outer ul. The ul doesn't have an actual height because all the lis are floated.
.headerprofile .ULlist ul {
list-style:none;
padding:0 10px;
}
.headerprofile .ULlist ul li {
float:left;
position:relative;
}
I think this line will solve your problem
headerprofile .ULlist ul li:hover > ul
{
display:block;
margin-top:30px; /* add this line to your css*/
}
DEMO
You can fix this if you add: top: 30px; to your submenu.
Demo