here is what's happening.
As required!
http://jsfiddle.net/U99Br/
So I'm making this web site with a drop down menu, until now it was all good, but while doing my drop-down menu (I wanted to do something of the sort of Netflix's menu), I noticed my sub-menu is pushing the "contact" li tag 300px away (which is it's length).
Here's my code:
#menu,
#menu ul,
#menu li {
margin: 0;
padding: 0;
list-style: none;
}
#menu a {
text-decoration: none;
}
#menu {
height: 60px;
width: auto;
}
#menu > ul > li {
float: left;
margin-left: 15px;
position: relative;
}
#menu > ul > li > a {
color: #fff;
text-shadow: 1px 1px 5px #737373;
font-size: 20px;
line-height: 60px;
padding: 15px 20px;
}
#menu > ul > li > a:hover {
color: #000;
}
#menu > ul > li > ul {
opacity: 0;
visibility: hidden;
display: none;
background-color: #fff;
text-align: left;
height: auto;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.4);
width: 300px;
}
#menu > ul > li:hover > ul {
display: block;
border: none;
visibility: visible;
opacity: 1;
}
#menu > ul > li > ul > li {
display: block;
content: '';
}
#menu > ul > li > ul > li > a {
font-size: 12px;
color: #000;
display: block;
text-shadow: none;
}
#menu > ul > li > ul > li > a:hover {
color: #0AB3FC;
}
#menu > ul ul > li {
position: relative;
}
I have not found what's wrong in my coding yet!
ad a width to the first ul li so children can not push up width from parent
#menu > ul > li {
width:300px; /* add with here */
float: left;
margin-left: 15px;
position: relative;
}
Related
The hidden li (e.g. Space 01, Space 02) expands in height, when user visits the website for the first time.
Once user refreshes the browser, the height of li will look just fine.
How do I fix this issue? This problem only exists in IE browsers.
#cssmenu {
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, Sans-Serif;
font-size: 13px;
line-height: 26px;
text-align: left;
}
#cssmenu > ul {
width: auto;
list-style-type: none;
padding: 0;
margin: 0;
background: #ffffff;
border: 1px solid #ece6e8;
border-bottom: 3px solid #d9ced2;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
border-radius: 2px;
list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);
}
#cssmenu > ul li#responsive-tab {
display: none;
/* Hide for large screens */
}
#cssmenu > ul li {
display: inline-block;
border-right: 1px solid #F1F1F1;
*display: inline;
zoom: 1;
}
#cssmenu > ul li.right {
float: right;
}
#cssmenu > ul li.has-sub {
position: relative;
}
#cssmenu > ul li.has-sub:hover ul {
display: block;
}
#cssmenu > ul li.has-sub ul {
display: none;
width: 250px;
position: absolute;
margin: 0;
padding: 0;
list-style-type: none;
background: #ffffff;
border: 1px solid #ece6e8;
border-bottom: 3px solid #d9ced2;
border-top: 0 none;
}
#cssmenu > ul li.has-sub ul li {
display: block;
border-bottom: 1px solid #f1f1f1;
}
#cssmenu > ul li.has-sub > a {
background-image: url('caret.png');
background-repeat: no-repeat;
background-position: 90% -330%;
}
#cssmenu > ul li.has-sub > a.active,
#cssmenu > ul li.has-sub > a:hover {
background: #009FDA url('caret.png') no-repeat;
background-position: 90% 430%;
}
#cssmenu > ul li a {
display: block;
padding: 12px 24px 11px 17px;
text-decoration: none;
color: #747474;
}
#cssmenu > ul li a.active,
#cssmenu > ul li a:hover {
background: #009FDA;
color: #fff;
}
#media (max-width: 600px) {
#cssmenu > ul {
width: 100%;
}
#cssmenu > ul li#responsive-tab {
display: block;
}
#cssmenu > ul li#responsive-tab a {
background: url('images/menu.png') no-repeat;
background-position: 95% -35%;
}
#cssmenu > ul li#responsive-tab a:hover {
background-color: #009FDA;
background-position: 95% -35%;
}
#cssmenu > ul li {
display: none;
}
#cssmenu > ul li.right {
float: none;
}
#cssmenu > ul li.has-sub {
position: relative;
}
#cssmenu > ul li.has-sub ul {
display: block;
position: static;
width: 100%;
background: #ffffff;
border: 0 none;
}
#cssmenu > ul li.has-sub ul li {
display: block !important;
}
#cssmenu > ul li.has-sub ul li a span {
display: block;
}
#cssmenu > ul li.has-sub > a {
background-image: none;
}
}
/* Make sure they show even if hidden in mobile view by JS */
#media (min-width: 600px) {
#cssmenu > ul > li.collapsed {
display: inline-block !important;
*display: inline;
zoom: 1;
}
#cssmenu > ul ul li.collapsed {
display: block !important;
}
}
<html>
<div id="cssmenu">
<ul>
<li class="has-sub">
<a href="#">
<span class="navi"><img src="http://www.kclibrary.org/sites/all/themes/kcplibraryzen/images/menu_items/menu-icon.png"></span>
<span>Test Dropdown</span></a>
<ul>
<li>
<span>Space 01</span></li>
<li class="last">
<span>Space 02</span></li>
</ul>
</li>
</ul></div>
</html>
When I hover over the html section the html & css nav option is moved to the right for some reason, how do I get it to align with the other nav options.
http://codepen.io/anon/pen/bEqPRQ
#nav {
list-style: none;
text-align: center;
padding: 1.250em 0 1.250em 0;
background: #ffffff;
font-size: 106.25%;
font-family: 'Oxygen';
}
#nav li a {
text-decoration: none;
text-align: center;
color: #FFF;
}
#nav ul li ul.dropdown {
background-color: #000000;
display: none;
position: fixed;
z-index: auto;
left: 400;
vertical-align: left;
}
#nav ul li:hover ul.dropdown {
display: block;
}
#nav ul li ul.dropdown li {
display: block;
}
#nav > ul > li {
display: inline-block;
margin-right: 2%;
padding: 4.375em 1.250em 4.375em 1.250em;
}
#nav > ul > li > a {
text-decoration: none;
color: #000000;
}
#nav > ul > li > a:hover {
color: #00c5a2;
}
Your <ul> has a default styling (padding-left) which has to be removed. Adding
#nav ul li ul.dropdown {
padding-left: 0;
}
moves your text to the left.
You should also check your CSS, vertical-align: left and left: 400 (doesn't have a unit) aren't valid and won't work.
You can solve the problem adding padding left = 0 in the css of #nav ul li ul.dropdown :
#nav ul li ul.dropdown {
padding-left: 0;
}
Try changing the .dropdown style as follows:
#nav ul li ul.dropdown {
background-color: #000000;
display: none;
position: absolute;
z-index: auto;
left: 0;
vertical-align: left;
}
Then the parent li position to relative:
#nav > ul > li {
display: inline-block;
margin-right: 2%;
padding: 4.375em 1.250em 4.375em 1.250em;
position: relative;
}
This ensures the dropdown always positions itself absolute to its parent (the li).
Also adding padding: 0 to the dropdown ul:
#nav ul li:hover ul.dropdown {
display: block;
padding: 0;
}
Fiddle: https://jsfiddle.net/04zospoj/
I've tried a bunch of techniques to solve this. I've used float (left/right) and played with positioning (absolute & relative). None worked.
Basically my navigation keeps moving when the the text decoration (font-weight: bold; in this case) is applied.
I'm new to CSS and this is my first header- so any feedback on the header/site-navigation as a whole is welcome. My second layer nav (ul ul) seems to be lining up vertically, and seems to be using effects from the previous layer. This needs fixing too.
Here is my code:
.main-navigation {
left:50%;
transform: translateX(-50%);
position: absolute;
padding-top:0em;
margin: 0px auto;
z-index: 999;
border-top: 2px solid;
border-bottom: 1px solid;
display: inline-block;
}
.main-navigation-body {
width:1000px;
margin-left:auto;
margin-right:auto;
text-align: center;
}
.main-navigation-body ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.main-navigation-body a {
color:black;
}
.main-navigation-body a:visited {
}
.main-navigation li {
display: inline-block;
text-align: center;
padding:1.64em;
padding-top: 0.3em;
padding-bottom: 0.3em;
}
.main-navigation a {
text-decoration: none;
}
.main-navigation ul ul {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
position: absolute;
top: 2.0em;
left: -999em;
z-index: 99999;
background-color:pink;
width: 100px;
text-align:left;
}
.main-navigation ul ul ul {
left: -999em;
top: 0;
}
.main-navigation ul ul a {
}
.main-navigation ul ul li {
display: inline-block;
border-top: 0px solid;
border-bottom: 0px solid;
padding:0.1em;
}
.main-navigation li:hover > a,
.main-navigation li.focus > a {
font-weight: bold;
}
.main-navigation ul ul :hover > a,
.main-navigation ul ul .focus > a {
}
.main-navigation ul ul a:hover,
.main-navigation ul ul a.focus {
font-weight: bold;
}
.main-navigation ul li:hover > ul,
.main-navigation ul li.focus > ul {
left: auto;
}
.main-navigation ul ul li:hover > ul,
.main-navigation ul ul li.focus > ul {
left: 100%;
}
.main-navigation .current_page_item > a,
.main-navigation .current-menu-item > a,
.main-navigation .current_page_ancestor > a {
font-weight: bold;
color: #BB9A69;
}
Here is the website
Thanks,
This is normal behaviour: Bold text is wider, thus repositioning the centered text around it.
You could go for a fixed width on all links to prevent this:
.main-navigation a {
text-decoration: none;
min-width: 6em;
display: inline-block;
}
I have a drop down menu and when you hover over an option it shows the submenu, but then when you move the cursor down; sometimes the rest of the menu will hide. I have noticed there is a little bit of space (margin? border?) underneath that I am assuming is the culprit unless someone can tell me differently.
Below is an image to show what I mean; there is a small gap between the two options and I am assuming when you make the cursor go over that point it comes off "hover" and hides it
Any help would be greatly appreciated.
.menu ul { margin = ..;}
The above code makes the margin bigger, however even when it is set to 0 it still seems to be there..
This is my HTML for the menu
<td align="center" bgcolor="#666666">
<div class="menu" align="center">
<ul>
<li>Bar Equipment
<ul>
<li>Tills</li>
<li>Bar Furniture</li>
<li>Bar Sundries</li>
...
</div></td>
This is the Css for the menu class
#charset "utf-8";
* {
margin: 0px; padding: 0px;
}
.menu {
margin: 0px;
text-align: center;
background: #efefef;
padding: 0px;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
background: #efefef;
padding: 0;
list-style: none;
position: relative;
display: inline-table;
margin: 0px;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
}
.menu ul li:hover {
background: #999;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
display: block;
padding: 10px;
color: #757575;
text-decoration:none;
}
.menu ul ul {
background: #efefef;
padding: none;
position: absolute;
top: 100%; /* ?? */
}
.menu ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color:#fff;
display: block;
}
.menu ul ul li a:hover {
background: red;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul ul li a {
padding: 10px;
color: #fff;
}
.menu ul ul ul li a:hover {
background: red; */
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
}
see the jsfiddle: http://jsfiddle.net/p1kuzzdo/
try this css:
#charset "utf-8";
* {
margin: 0px; padding: 0px;
}
.menu {
background: none repeat scroll 0 0 #efefef;
height: 50px;
line-height: 50px;
margin: 0;
padding: 0;
text-align: center;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
height: 50px;
line-height: 50px;
list-style: outside none none;
margin: 0;
padding: 0;
position: relative;
text-align: center;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
padding: 0 10px;
}
.menu ul li:hover {
background: #999;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
color: #757575;
display: block;
text-decoration: none;
}
.menu ul ul {
background: none repeat scroll 0 0 #efefef;
padding: 0;
position: absolute;
top: 100%;
}
.menu ul ul li {
border-bottom: 0 solid pink;
border-top: 0 solid #6b727c;
float: none;
margin: 0;
padding: 0;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color:#fff;
display: block;
}
.menu ul ul li a:hover {
background: red;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul ul li a {
color: #fff;
}
.menu ul ul ul li a:hover {
background: red; */
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
}
I've set the DIV height to 54px but for some reason the UL is only about half of that - all the navigation links are way up at the top of the div for some reason.
<div id="menu">
<ul class="left" style="display: none;">
<li id="dashboard"><?php echo $text_dashboard; ?></li>
</u>
</div>
Here's what's in my CSS that I think pertains to this:
#menu {
background: url('../image/menu.png') repeat-x;
position: relative;
z-index: 1;
height: 54px;
clear: both;
padding: 0px 30px;
min-width: 900px;
}
#menu > ul.left {
float: left;
}
#menu > ul.right {
float: right;
}
#menu > ul {
position: relative;
margin: 0;
padding: 0;
}
#menu > ul ul {
list-style: none;
margin: 0;
padding: 0;
background: url('../image/transparent.png');
}
#menu > ul a {
display: block;
text-decoration: none;
}
#menu > ul li {
float: left;
list-style: none;
}
#menu > ul > li + li {
background: url('../image/split.png') center left no-repeat;
}
#menu > ul .top {
padding: 10px 15px 9px 17px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
text-align: center;
}
#menu > ul li ul {
position: absolute;
}
#menu > ul ul li {
padding: 2px;
clear: both;
}
#menu > ul .selected .top {
background: url('../image/selected.png') repeat-x;
color: #FFFFFF;
}
#menu > ul .parent {
background-image: url('../image/arrow-right.png');
background-position: 95% center;
background-repeat:no-repeat;
}
#menu > ul li ul ul {
margin: -29px 0 0 161px;
}
#menu > ul li li a {
padding: 5px;
margin: 1px;
color: #FFFFFF;
width: 147px;
}
#menu > ul li li > a:hover {
margin: 0px;
border: 1px solid #BD4C14;
background-color: #391706;
}
Any idea what needs to be changed to extend the height of the UL like I did the DIV?