I've got a simple dropdown css menu, which is positioned in the footer and with upwards direction - fiddle: http://jsfiddle.net/RmTpc/11/
i would like for opened menu to have some bottom margin from the main li ("Items"), but when i apply margin-bottom: 30px to the ul.dropdown ul, opened menu dissapears on hover.
I've googled and also tried answers from stackoverflow:
Drop down menu with margin-top
How to use (top) margin with CSS3 drop down menu?
but can't get it to work. Any help appriciated, thanks :)
EDIT: Sorry, posted wrong fiddle before, updated the link above.
The problem lies with the margin - it's effectively 'dead space' so you're not actually touching it when you move the mouse up towards it.
I think the best solution is to remove the margin, and add the 30px to the bottom padding of the ul (so you're touching it when you mouseover), and remove the background color:
ul.dropdown ul {
left: 0;
position: absolute;
top: 100%;
visibility: hidden;
z-index: 999;
margin: 0;
width: 300px;
padding: 20px 20px 50px;
opacity: 0;
-ms-filter: "alpha(opacity=0)";
filter: alpha(opacity=0);
}
(see http://jsfiddle.net/RmTpc/3/)
You'll probably need to adjust the padding of the list items to make up for the lost background space, but this solution should work for you.
EDIT:
Using the updated JSFiddle, you'll need to move your borders to the 'li' elements as well. See the New JSFiddle I set up, or this code:
ul.dropdown ul {
left: 0;
position: absolute;
top: 100%;
visibility: hidden;
z-index: 999;
margin: 0;
width: 300px;
padding: 20px 20px 50px;
opacity: 0;
-ms-filter: "alpha(opacity=0)";
filter: alpha(opacity=0);
}
ul.dropdown ul li {
float: none;
background: #fff;
border: solid 2px #bbb;
border-top: none;
border-bottom: none;
}
ul.dropdown ul li:first-child {
border-top: 2px solid #bbb;
}
ul.dropdown ul li:last-child {
border-bottom: 2px solid #bbb;
}
Have a look at following CSS:
http://jsfiddle.net/RmTpc/15/
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 100px;
height: 100%;
}
footer {
position: fixed;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
background: #222;
z-index: 999;
padding-left: 40px;
}
ul#nav {
font-family: Arial, Helvetica;
font-weight: 300;
}
ul.dropdown, ul.dropdown li {
list-style: none outside none;
margin: 0;
padding: 0;
}
ul.dropdown {
float: left;
position: relative;
z-index: 999;
}
ul.dropdown li {
float: left;
line-height: 1.3em;
min-height: 1px;
vertical-align: middle;
}
ul.dropdown li.hover, ul.dropdown li:hover {
cursor: default;
position: relative;
z-index: 600;
}
ul.dropdown ul {
left: 0;
position: absolute;
top: 100%;
visibility: hidden;
z-index: 999;
margin: 0;
width: 300px;
padding-bottom: 30px;
padding-left: 0;
opacity: 0;
-ms-filter: "alpha(opacity=0)";
filter: alpha(opacity=0);
}
ul.dropdown li:hover > ul {
visibility: visible;
-ms-filter: "alpha(opacity=100)";
filter: alpha(opacity=100);
opacity:1;
zoom: 1;
}
ul.dropdown ul li {
float: none;
background: #fff;
border-left: solid 2px #bbb;
border-right: solid 2px #bbb;
padding-left: 20px;
padding-right: 20px;
}
ul.dropdown ul li:first-child {
border-top: solid 2px #bbb;
padding-top: 20px;
}
ul.dropdown ul li:last-child {
border-bottom: solid 2px #bbb;
padding-bottom: 20px;
}
ul.dropdown ul ul {
left: 99%;
top: 1px;
}
ul.dropdown-upward ul {
bottom: 100%;
top: auto;
}
ul.dropdown li {
color: #fff;
background: #222;
padding: 7px 10px;
}
ul.dropdown li.hover, ul.dropdown li:hover, ul.dropdown li.on {
color: #bbb;
}
ul.dropdown a:link, ul.dropdown a:visited {
color: #000000;
text-decoration: none;
}
ul.dropdown a:hover {
color: #000000;
}
ul.dropdown a:active {
color: #FFA500;
}
ul.dropdown ul li {
font-weight: normal;
}
Your menu will look like you have done it so far. One difference is that I replaced the margin with padding.
UPDATE: I have updated the CSS Code
Put the margin-bottom: 30px in the ul.dropdown ul li block and not for ul.dropdown ul. I think that'll make it work.
Related
After creating a navigation bar, I discovered a transparent box around it, which has some transparent features. Though it's not strikingly noticeable, I would still like to remove it. I've attached an image and the CSS code. I think the .menu tag is creating the transparent box, but I don't know how to remove it.
/* Navigation */
.clearfix {
width: 595px;
}
.clearfix:after {
display: block;
clear: both;
}
.menu-wrap {
width: 80px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.2);
position: absolute;
top: 5.5%;
left: 55%;
}
.menu {
width: 100%;
margin: 0px;
right: 10px;
}
.menu li {
margin: 0px;
list-style: none;
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
}
.menu a {
transition: all linear 0.15s;
color: #ffffff;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration: none;
color: #000000;
}
.menu .arrow {
font-size: 11px;
line-height: 0%;
}
/* Top Level */
.menu > ul > li {
float: left;
display: inline-block;
position: relative;
font-size: 1em;
}
.menu > ul > li > a {
padding: 10px 30px;
display: inline-block;
text-decoration: none;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background: #ffffff;
}
/* Bottom Level */
.sub-menu {
width: 140%;
padding: 5px 0px;
position: absolute;
top: 100%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
box-shadow: 0px 2px 3px rgba(0,0,0,0.2);
background: #ffffff;
}
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu li {
display: block;
font-size: 1em;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
color: #000000;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background: #e0e0e0;
}
I played around with it a little and figured it out, but anyone else can feel free to comment if my answer isn't satisfactory.
The problem was actually caused by the .menu-wrap tag, and all I had to do to remove it was remove the box-shadow: 0px 1px 3px rgba(0,0,0,0.2); attribute I added to the code. It seems this transparent box had problems with the box-shadow property.
I'm testing dropdown nav bar with pure css. Text-align doesn't work it only align the dropdown text, left: 50% and right: 50% yes it makes the text center but the navbar won't cover the width of my page. and please don't use overflow: hidden it will make the dropdown not visible
JSFiddle
I want to make the text like this but because of the overflow I can't see the dropdown
Css:
ul.dropdown, ul.dropdown li, ul.dropdown ul {
list-style: none;
margin: 0;
padding: 0;
}
ul.dropdown {
position: relative;
z-index: 597;
background-color: black;
}
ul.dropdown li {
float: left;
min-height: 1px;
line-height: 1.3em;
vertical-align: middle;
}
ul.dropdown li.hover, ul.dropdown li:hover {
position: relative;
z-index: 599;
cursor: default;
}
ul.dropdown ul {
visibility: hidden;
position: absolute;
top: 100%;
left: 0;
z-index: 598;
width: 100%;
}
ul.dropdown ul li {
float: none;
}
ul.dropdown ul ul {
top: 1px;
left: 99%;
}
ul.dropdown li:hover > ul {
visibility: visible;
}
/* -- Base drop-down styling -- */
ul.dropdown {
font: normal 16px"Square", Arial, Helvetica, sans-serif;
text-transform: uppercase;
width: 100%;
}
ul.dropdown li {
padding: 7px 0;
background-color: #000;
color: #fff;
line-height: normal;
}
ul.dropdown a:link, ul.dropdown a:visited {
color: #fff;
text-decoration: none;
}
ul.dropdown a:hover {
color: #005CE6;
text-decoration: none;
}
ul.dropdown a:active {
color: #fff;
}
/* -- level mark -- */
ul.dropdown ul {
width: 170px;
background-color: #333;
color: #fff;
font-size: 12px;
text-transform: none;
filter: alpha(opacity=90);
-moz-opacity: .9;
KhtmlOpacity: .9;
opacity: .9;
}
ul.dropdown ul li {
background-color: transparent;
color: #000;
filter: none;
}
ul.dropdown ul li.hover, ul.dropdown ul li:hover {
background-color: transparent;
}
ul.dropdown ul a:link, ul.dropdown ul a:visited {
color: #fff;
}
ul.dropdown ul a:hover {
color: #fff;
text-decoration: none;
}
ul.dropdown ul a:active {
color: #fff;
}
/* -- Supporting class `dir` -- */
ul.dropdown *.dir {
padding-right: 12px;
background-image: none;
background-position: 100% 50%;
background-repeat: no-repeat;
}
/* -- Base style extension -- */
ul.dropdown li a {
display: block;
padding: 7px 14px;
}
/* -- Base style override -- */
ul.dropdown li {
padding: 0;
}
/* -- Base style reinitiate: post-override activities -- */
ul.dropdown li.dir {
padding: 7px 20px 7px 14px;
}
ul.dropdown ul li.dir {
padding-right: 15px;
}
/* -- Custom -- */
ul.dropdown ul a {
padding: 4px 5px 4px 14px;
width: 151px;
/* Especially for IE */
}
ul.dropdown ul a:hover {
background-color: #005CE6;
}
/* -- Drop-down open -- */
ul.dropdown li:hover > a.dir {
background-color: #2e2e2e;
color: #005CE6;
}
ul.dropdown ul li:hover > a.dir {
background-color: #76b900;
color: #fff;
}
html {
*overflow-x: hidden;
}
body {
padding: 0;
}
body, html {
height: 100%;
padding: 0;
margin: 0;
}
.wrapper {
min-height: 100%;
width: 100%
overflow: hidden;
}
.container {
padding: 50px;
}
.horizontal-centering {
position: relative;
}
.horizontal-centering > * > * {
float: left;
width: 100%;
position: relative;
margin: 0;
padding: 0;
}
.horizontal-centering > * > * > * {
float: left;
position: relative;
}
remove float: left; in your ul.dropdown li. Add text-align: center; in your ul.dropdown and display: inline-block; in your ul.dropdown li
Fiddle Demo
ul.dropdown {
position: relative;
z-index: 597;
background-color: black;
text-align: center;
}
ul.dropdown li {
display: inline-block;
min-height: 1px;
line-height: 1.3em;
vertical-align: middle;
}
I want to make my navigation bar stretch the full width of my page, but it doesnt want to stretch everytime I use width 100% the navbar just break and lose its form. I'm not using any javascript and i think the problem is on the .horizontal-centering class CMIW
JSFiddle
I'm using pure css nav bar
/* dropdown.css */
ul.dropdown, ul.dropdown li, ul.dropdown ul {
list-style: none;
margin: 0;
padding: 0;
}
ul.dropdown {
position: relative;
z-index: 597;
float: left;
}
ul.dropdown li {
float: left;
min-height: 1px;
line-height: 1.3em;
vertical-align: middle;
}
ul.dropdown li.hover, ul.dropdown li:hover {
position: relative;
z-index: 599;
cursor: default;
}
ul.dropdown ul {
visibility: hidden;
position: absolute;
top: 100%;
left: 0;
z-index: 598;
width: 100%;
}
ul.dropdown ul li {
float: none;
}
ul.dropdown ul ul {
top: 1px;
left: 99%;
}
ul.dropdown li:hover > ul {
visibility: visible;
}
/* default.css */
ul.dropdown {
font: normal 16px"Square", Arial, Helvetica, sans-serif;
text-transform: uppercase;
}
ul.dropdown li {
padding: 7px 0;
background-color: #000;
color: #fff;
line-height: normal;
}
ul.dropdown a:link, ul.dropdown a:visited {
color: #fff;
text-decoration: none;
}
ul.dropdown a:hover {
color: #005CE6;
text-decoration: none;
}
ul.dropdown a:active {
color: #fff;
}
ul.dropdown ul {
width: 170px;
background-color: #333;
color: #fff;
font-size: 12px;
text-transform: none;
filter: alpha(opacity=90);
-moz-opacity: .9;
KhtmlOpacity: .9;
opacity: .9;
}
ul.dropdown ul li {
background-color: transparent;
color: #000;
filter: none;
}
ul.dropdown ul li.hover, ul.dropdown ul li:hover {
background-color: transparent;
}
ul.dropdown ul a:link, ul.dropdown ul a:visited {
color: #fff;
}
ul.dropdown ul a:hover {
color: #fff;
text-decoration: none;
}
ul.dropdown ul a:active {
color: #fff;
}
ul.dropdown *.dir {
padding-right: 12px;
background-image: none;
background-position: 100% 50%;
background-repeat: no-repeat;
}
/* default.advanced.css */
ul.dropdown li a {
display: block;
padding: 7px 14px;
}
ul.dropdown li {
padding: 0;
}
ul.dropdown li.dir {
padding: 7px 20px 7px 14px;
}
ul.dropdown ul li.dir {
padding-right: 15px;
}
ul.dropdown ul a {
padding: 4px 5px 4px 14px;
width: 151px;
}
ul.dropdown ul a:hover {
background-color: #005CE6;
}
ul.dropdown li:hover > a.dir {
background-color: #2e2e2e;
color: #005CE6;
}
ul.dropdown ul li:hover > a.dir {
background-color: #76b900;
color: #fff;
}
html { *overflow-x: hidden; }
body { padding: 0; }
body, html { height: 100%; padding: 0; margin: 0; }
.wrapper { min-height: 100%; min-width: 950px;overflow: hidden; }
.container { padding: 50px; }
.horizontal-centering { position: relative; }
.horizontal-centering > * > * { float: left; width: auto; position: relative; left: 50%; margin: 0; padding: 0; }
.horizontal-centering > * > * > * { float: left; position: relative; right: 50%; }
Instead of using overflow hidden to clear the floats by using a clearfix helper class this made the second level appear.
/* helper class for clearing floats */
.clearfix:after{
display: block;
visibility: hidden;
clear: both;
height: 0;
content:".";
}
.clearfix {
display: inline-block;
}
.clearfix{
display: block;
}
Reworked the dropdown and centering a little
.horizontal-centering {
background: #000000;
position: relative;
}
.horizontal-centering > div > div {
clear: both;
float: left;
width: 100%;
}
.dropdown-horizontal {
float: left;
width: auto;
position: relative;
left: 50%;
margin: 0;
padding: 0;
}
ul.dropdown > li > ul {
visibility: hidden;
position: absolute;
width: auto;
left: 0;
}
ul.dropdown > li:hover > ul {
visibility: visible;
}
ul.dropdown, ul.dropdown li, ul.dropdown ul {
list-style: none;
margin: 0;
padding: 0;
}
ul.dropdown {
float: left;
left: 50%;
list-style-type: none;
margin: 0 auto;
padding: 0;
position: relative;
}
ul.dropdown > li {
float: left;
position: relative;
right: 50%;
line-height: 1.3em;
}
ul.dropdown li.hover, ul.dropdown li:hover {
cursor: default;
}
ul.dropdown ul li {
float: none;
}
http://fiddle.jshell.net/35JPL/26/
http://fiddle.jshell.net/35JPL/26/show/
Check this fiddle based on yours: http://jsfiddle.net/u67qx/
I added width:100% to some classes and I deleted left:50%; and right:50%;. Looks like this is what you want. You can align text to center.
I am facing some problem with this drop down menu thing. I read your article and it helped me. In the beginning, the drop down worked but when I added some more styling then it stopped working. Other divs and navigation bar is working fine but the drop down menu is not working. Can you please help me pointing out what should be corrected here?
The parent div is nav-bar-left and the style is
.nav-bar-left {
float; left;
overflow: hidden;
width: 980px;
height: 26px;
background-color: Lavender;
border: 1px solid MidnightBlue;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
The navigation div is #horizontalmenu which resides within the above parent div and the style is
#horizontalmenu {
width: 733px;
margin: 0;
position: relative;
float: left;
padding: 0;
}
Rest of the styling for navigation bar is
#navbar {
list-style-type: none;
margin: 0;
width: 100%;
padding: 0;
position: relative;
display: inline-table;
height: 26px;
z-index: 5;
}
#navbar li {
float: left;
position: relative;
}
#navbar a:link, #navbar a:visited {
display: block;
color: #333;
background-color: lavender;
text-align: center;
padding: 6px 10px;
border-style: solid;
border-color: MidnightBlue;
border-width: 0 1px 0 0;
text-decoration: none;
font-size: 14px;
line-height: 14px;
}
#navbar a:hover, #navbar a:active {
color: #fff;
background-color: #6b0c36;
text-decoration: underline;
}
#navbar ul {
left:-9999px;
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
#navbar ul li {
float:none;
border-style: solid;
border-color: Lavender;
border-width: 0 1px 1px 1px;
}
#navbar ul a {
white-space: nowrap;
}
#navbar li:hover ul {
left: 0;
}
#navbar:hover a {
text-decoration: none;
}
#navbar li:hover ul a {
text-decoration: none;
background-color: Lavender;
color: #333;
}
#navbar li:hover ul li a:hover {
background-color: Lavender;
color: #333;
}
So, why is it not working and what can be done?
I found this menu CSS one of my best collection for dropdown menu:
Create a Multilevel Dropdown menu with CSS and improve it via jQuery
And you can find a backup of those codes here in my pastebin.
i am trying to create a drop-down menu with rounded corners and have nearly got there but for a small issue in IE. If you view this link (http://ids-ind.com/koris/dropdown.html) in FF it looks and works fine but in IE the right hand side has a flat top.
Please can you advise what i need to do/change to get it looking like it does in FF?
Below is the CSS i am using
a:link {text-decoration:none;}
/* tabs
*************************/
ul.tabs
{
display: table;
margin: 0;
padding: 0;
list-style: none;
position: relative;
}
ul.tabs li
{
margin: 0 0 0 1px;
padding: 0;
list-style: none;
display: table-cell;
float: left;
position: relative;
background:url('../images/menuleft_bg.png') left bottom no-repeat;
line-height:55px;
width:130px;
}
ul.tabs a
{
position: relative;
display: block;
background:url('../images/menuright_bg.jpg') right bottom no-repeat;
}
/* dropdowns
*************************/
ul.dropdown
{
margin: 0;
padding: 0;
display: block;
position: absolute;
z-index: 999;
top: 100%;
width: 130px;
display: none;
left: 0;
}
ul.dropdown ul.dropdown
{
top: 0;
left: 100%;
}
ul.dropdown li
{
margin: 0;
padding: 0;
float: none;
position: relative;
list-style: none;
display: block;
}
ul.dropdown li a
{
display: block;
}
/* menu-specifc
*************************/
#menu
{
position: fixed;
z-index: 5;
top: 0;
left: 0;
height: 40px;
line-height: 40px;
border-bottom: 0px solid #000;
}
#menu ul
{
margin: 0 auto;
}
#menu ul li h4
{
margin: 0;
}
#menu ul li h4 a
{
font-size: 14px;
color: #000;
font-weight: bold;
padding: 0 15px;
}
#menu ul li a
{
color: #fff;
padding-left: 4px;
}
#menu ul li a img
{
vertical-align: middle;
}
#menu ul li a span
{
display: block;
padding: 0 20px;
text-align:center;
}
#menu ul.dropdown
{
padding: 20px 0;
background-image: url('../images/dropdownbg.png');
overflow:hidden;
border-bottom: 0px solid #dc902f;
width: 130px;
z-index:110;
}
#menu ul.dropdown li a
{
border-bottom: 0px solid #e5cd8e;
line-height: 30px;
overflow: hidden;
height: 30px;
background-image: url('../images/dropdownbg2.png');
}
#menu ul.dropdown li.last a
{
border-bottom-width: 0;
}
#menu ul.dropdown li a:hover
{
color:#990000;
}
#menu ul li h4 a:hover
{
background-image: none;
}
remove the position:relative; in below
ul.tabs a{}