CSS nested menu is not aligned properly - html

I have a basic nested menustruct:
http://jsfiddle.net/vqnUP/
#topmenu
{
min-height: 54px;
width: 980px;
margin: 0 auto;
background-color: green;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
}
#topmenu ul
{
list-style-type: none;
margin: 0 0 0 0;
padding: 13px 0 0 0;
color: #fff;
font-size: 1.6em;
}
#topmenu ul li
{
display: inline;
padding: 15px 2.5% 17px 2.5%;
margin: 0 0 0 0;
border-right: 1px solid #000;
box-shadow: 1px 0px 0px #6e6b6b;
position: relative;
}
#topmenu ul li:last-child
{
border: none;
box-shadow: none;
}
#topmenu ul li:first-child
{
border-top-left-radius: 15px;
}
#topmenu ul li img
{
vertical-align: middle;
}
#topmenu a
{
color: #fff;
text-decoration: none;
height: 54px;
}
#topmenu ul li ul{
display: none;
list-style-type: none;
margin: 0 0 0 0;
padding: 13px 0 0 0;
color: #fff;
font-size: 1.6em;
position: absolute;
z-index: 1000;
background-color: red;
}
#topmenu ul li:hover ul{
display: block;
}
#topmenu ul li ul li{
display: block;
padding: 15px 2.5% 17px 2.5%;
margin: 0 0 0 0;
border-right: 1px solid #000;
box-shadow: 1px 0px 0px #6e6b6b;
font-size: 14px;
}
#topmenu ul li ul li:last-child{
border: none;
box-shadow: none;
}
#topmenu ul li ul li:first-child{
border-top-left-radius: 15px;
}
#topmenu ul li ul li img{
vertical-align: middle;
}
<div id="topmenu">
<ul>
<li class=""><a href="home"><img src='/assets/upload/pagemenu/home.png' /></li>
<li class="">Tanßr</li>
<li class="">Dißk</li>
<li class="">SzŘl§</li>
<li class="">Nyelviskola</li>
<li class="">
Boltok
<ul>
<li class="">aaaaaaaa</li>
<li class="">aaaaaaaaa</li>
</ul>
</li>
<li class="">Kapcsolat</li>
<li class="">Linkek</li>
<li class="kiemelt">Webshop</li>
</ul>
<div style="clear: both;"></div></div>
its almost OK, but the submenu in "Boltok" (containing aaaaaaa) doesnt appear excatly under the "Boltok" menu, but aligned to left. I can't figure out the mistake...

I added a top and left to your sub menu
#topmenu ul li ul{
display: none;
list-style-type: none;
margin: 0 0 0 0;
padding: 13px 0 0 0;
color: #fff;
font-size: 1.6em;
position: absolute;
z-index: 1000;
background-color: red;
top: 62px; /* added */
left: 0; /* added */
width: 100%; /* this will cause the submenu to take the 100% width of the containing li - optional? */
};
So we only target the first ul li's you change this class like this. Also added a float: left and changed the display to block
#topmenu > ul > li
{
display: block; float: left;
padding: 15px 2.5% 17px 2.5%;
margin: 0 0 0 0;
border-right: 1px solid #000;
box-shadow: 1px 0px 0px #6e6b6b;
position: relative;
}
Here's the updated fiddle: http://jsfiddle.net/vqnUP/2/

jsFiddle
I'm only addressing the issue you mentioned.
I have just added
width:100%; to #topmenu ul li ul and
text-align:center; to #topmenu ul li ul li.
Hope that helps...

Related

How to horizontally and vertically center a navbar?

I want to make my navbar directly in the middle of the page. So as i scroll down the rest of my content appears from beneath. Could someone please help and also explain how to position my background image to fixed so as i scroll the background doesn't move and lose its quality in resolution.
.menu-wrap {
width: 750px;
margin: 0 auto;
list-style: none;
}
/* DROPDOWN */
.ulMenu {
padding: 0;
margin: 0;
}
.navMenu ul {
padding: 0;
margin: 0;
line-height: 30px;
}
navMenu {
padding: 0;
margin: 0;
}
.navMenu li {
list-style-type: none;
padding: 0;
margin: 0;
float: left;
position: relative;
}
.navMenu ul li a {
text-align: center;
padding: 10px;
width: 150px;
height: 30px;
display: block;
color: white;
background-color: rgba(233, 233, 233, 0.5);
text-decoration: none;
border-radius: 0px;
font-family: 'Raleway', sans-serif;
font-size: 20px;
}
.navMenu ul ul {
position: absolute;
visibility: hidden;
}
.navMenu ul li:hover ul {
visibility: visible;
}
.ulMenu .arrow {
font-size: 10px;
}
.navMenu ul li:hover ul li a:hover {
background-color: rgba(93, 93, 93, 0.5);
}
.navMenu li:hover {
background-color: none;
}
.navMenu a:hover {
color: blue;
}
.navMenu ul li ul li {
padding: 2px 0 0 0;
}
.navMenu ul li {
padding: 0 2px 0 0;
}
/* DROPDOWN ENDED */
html {
background-image: url("indexImg.jpg");
background-size: cover;
}
<div class="menu-wrap">
<nav class="navMenu">
<ul class="ulMenu">
<li>Home
</li>
<li>
Products<span class="arrow">▼</span>
<ul>
<li>#
</li>
<li>#
</li>
</ul>
</li>
<li>Contact Us
</li>
<li>About
</li>
</ul>
</nav>
</div>
.menu-wrap {
position: relative;
}
.navMenu {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
I hope this is what u need
Check if it could complete your code
HTML
<nav>
<ul class="nav">
<li>Home</li>
<li>Product
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>Contact us
<li>About</li>
CSS
nav {
display: block;
text-align: center;
}
nav ul {
margin: 0;
padding:0;
list-style: none;
}
.nav a {
display:block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.8em 1.8em;
text-transform: uppercase;
font-size: 80%;
letter-spacing: 2px;
text-shadow: 0 -1px 0 #000;
position: relative;
}
.nav{
vertical-align: top;
display: inline-block;
box-shadow:
1px -1px -1px 1px #000,
-1px 1px -1px 1px #fff,
0 0 6px 3px #fff;
border-radius:6px;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
.nav > li > a {
margin-bottom: 1px;
box-shadow: inset 0 2em .33em -0.5em #555;
}
.nav > li:hover,
.nav > li:hover > a {
border-bottom-color: orange;
}
.nav li:hover > a {
color:orange;
}
.nav > li:first-child {
border-radius: 4px 0 0 4px;
}
.nav > li:first-child > a {
border-radius: 4px 0 0 0;
}
.nav > li:last-child {
border-radius: 0 0 4px 0;
margin-right: 0;
}
.nav > li:last-child > a {
border-radius: 0 4px 0 0;
}
.nav li li a {
margin-top: 1px;
}
.nav li a:first-child:nth-last-child(2):before {
content: "";
position: absolute;
height: 0;
width: 0;
border: 5px solid transparent;
top: 50% ;
right:5px;
}
.nav ul {
position: absolute;
white-space: nowrap;
border-bottom: 5px solid orange;
z-index: 1;
left: -99999em;
}
.nav > li:hover > ul {
left: auto;
margin-top: 5px;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
margin-left: 1px;
top: -1px;
}
/* arrow hover styling */
.nav > li > a:first-child:nth-last-child(2):before {
border-top-color: #aaa;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-bottom-color: orange;
margin-top:-5px
}
.nav li li > a:first-child:nth-last-child(2):before {
border-left-color: #aaa;
margin-top: -5px
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-right-color: orange;
right: 10px;
}

How to make border-right longer as <li> divider for menu?

Here's the js fiddle : http://jsfiddle.net/7dbemt0k/
I used below code to make divider.
box-shadow: 1px 0 #111111,
2px 0 #777777;
But I want it to be longer, from very top to very bottom across border-bottom.How do I increase the length or shall I use something like vertical tag? Please advise.Thanks.
HTML
<ul class="sf-menu">
<li>
<a href="<?php echo $data['config']['SITE_DIR']; ?>/">
<img src='<?php echo $data['config']['THEME_DIR']."/img/home_1.png"; ?>'></a>
</li>
<li>
About Us
<ul>
<li>
Centre-Point of Web Projects
</li>
</ul>
</li>
<li>
Branches
<?php Core::getHook('block-branches'); ?>
</li>
<li>
News
</li>
<li>
Events
</li>
<li>
Contact Us
</li>
</ul>
<div class="clear"></div>
CSS
/* Main */
.sf-menu {
width: 100%;
margin: 0;
padding: 10px 0 0 0;
list-style: none;
background-color: #2D2D2D;
/*background-image: linear-gradient(#444, #111);*/
border-bottom:6px solid #072438;
/*border-radius: 50px;*/
/* box-shadow: 0 2px 1px #9c9c9c;*/
box-shadow: 2px 1px #393939;
}
.sf-menu li {
float: left;
padding: 0 0 10px 0;
position: relative;
box-shadow: 1px 0 #111111,
2px 0 #777777;
border-bottom:6px solid #393939;
}
.sf-menu a {
float: left;
height: 20px;
padding: 0 25px;
color: #999;
/* text-transform: uppercase;*/
font: bold 12px/25px Arial, Helvetica;
text-decoration: none;
text-shadow: 0 1px 0 #000;
}
.sf-menu li:hover > a {
color: #fafafa;
}
*html .sf-menu li a:hover { /* IE6 */
color: #fafafa;
}
.sf-menu li:hover > ul {
display: block;
}
/* Sub-menu */
.sf-menu ul {
list-style: none;
margin: 0;
padding: 0;
display: none;
position: absolute;
top: 35px;
left: 0;
z-index: 99999;
background-color: #2D2D2D;
border-bottom:none;
/* background-image: linear-gradient(#444, #111); */
/*-moz-border-radius: 5px;*/
/*border-radius: 5px;*/
}
.sf-menu ul li {
float: none;
margin: 0;
padding: 0;
display: block;
box-shadow: 0 1px 0 #111111,
0 2px 0 #777777;
border-bottom:none;
}
.sf-menu ul li:last-child {
box-shadow: none;
}
.sf-menu ul a {
padding: 10px;
height: auto;
line-height: 1;
display: block;
white-space: nowrap;
float: none;
text-transform: none;
}
.sf-menu ul a:hover{
margin-left:10px;
}
*html .sf-menu ul a { /* IE6 */
height: 10px;
width: 150px;
}
*:first-child+html .sf-menu ul a { /* IE7 */
height: 10px;
width: 150px;
}
/* active menu*/
/*end */
.sf-menu ul a:hover {
/*background-color: #0186ba;
background-image: linear-gradient(#04acec, #0186ba);*/
}
.sf-menu ul li:first-child a {
/*border-radius: 5px 5px 0 0;*/
}
.sf-menu ul li:first-child a:after {
content: '';
position: absolute;
left: 30px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #072438;
}
.sf-menu ul li:first-child a:hover:after {
border-bottom-color: #072438;
}
.sf-menu ul li:last-child a {
/*border-radius: 0 0 5px 5px;*/
}
/* Clear floated elements */
.sf-menu:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.sf-menu ul li a:last-child{
box-shadow: 0 0 #111111,
0 0 #777777;
}
* html .sf-menu { zoom: 1; } /* IE6 */
*:first-child+html .sf-menu { zoom: 1; } /* IE7 */
remove padding: 10px 0 0 0; from .sf-menu and change the padding on .sf-menu li to padding: 10px 0;
FIDDLE
UPDATE
Because the box-shadow is outside of the element's natural width you just have to add some spacing to the li's using margin
.sf-menu li {
float: left;
padding: 10px 0;
margin: 0 0 0 2px; <---- //add margin
position: relative;
box-shadow: 1px 0 #111111,
2px 0 #777777;
border-bottom:6px solid #393939;
}
NEW FIDDLE
.sf-menu li {
float: left;
padding: 0 0 10px 0;
position: relative;
box-shadow: 1px 0px #111111,
2px 0 #777777;
border-bottom:6px solid #393939;
**height:40px;**
}
I don't quite understand yr question but u mentioned that u wanted to increase the vertical divider, you just have to set the height of the li

Level 2 submenu always visible

I have spent almost a whole day looking through various examples and still can't figure out a way of setting the 2 level submenu invisible. I got this template of the net and trying to customise it.
Here is the navigation bit from css file (I know it looks ugly ): )
#navigation { height: 35px; line-height: 35px; float: right; position: relative; z-index: 20; }
#navigation ul { list-style: none; list-style-position: outside; font-size: 13px; text-shadow: rgba(255,255,255,0.5) 0px 1px 1px; }
#navigation ul li { float: left; position: relative; padding-right: 2px; background: url(images/navigation-border.png) no-repeat right 0; }
#navigation ul > li.last { background: transparent; width: auto; float: left; padding-right: 0; }
#navigation ul > li.last a { border-radius: 0px 5px 5px 0px; -moz-border-radius: 0px 5px 5px 0px; -webkit-border-radius: 0px 5px 5px 0px; -o-border-radius: 0px 5px 5px 0px; border-right: 1px solid #d7e1e8 !important; }
#navigation ul > li.first a { border-radius: 5px 0px 0px 5px ; -moz-border-radius: 5px 0px 0px 5px ; -webkit-border-radius: 5px 0px 0px 5px ; -o-border-radius: 5px 0px 0px 5px; border-left: 1px solid #d7e1e8 !important; }
#navigation ul li a { color: #324957; float: left; padding: 0 18px; border: 1px solid #d7e1e8; border-left: 0; border-right: 0; background: url(images/navigation.png) repeat 0 0; }
#navigation ul li a:hover,
#navigation ul li.active a { background: url(images/navigation-a.png) repeat 0 0; color: #3995d6; text-decoration: none; }
#navigation ul li a span { background: url(images/navigation-arr.png) no-repeat right 0; width: 10px; height: 6px; float: right; padding-left: 3px; margin-top: 14px; }
#navigation ul li ul { display: none; float: none; line-height: 28px; position: absolute; top: 35px; left: 0; width: 100%; background: #e1efff; border-radius: 0px 0px 5px 5px; -moz-border-radius: 0px 0px 5px 5px; -webkit-border-radius: 0px 0px 5px 5px; -o-border-radius: 0px 0px 5px 5px; }
#navigation ul li:hover ul { visibility: visible; }
#navigation ul li ul li { display: block; float: none; padding: 0; background: transparent; }
#navigation ul li ul li a { float: none; display: block !important; padding: 0 18px; }
#navigation ul li ul li a:hover { float: none; display: block; background: transparent; background-color: #bdd7f4; }
#navigation ul li.last ul li a { padding: 0 18px !important; float: none; display: block; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; -o-border-radius: 0px;}
#navigation ul li ul li.last { float: none; display: block; }
#navigation ul li ul li.last a { border-radius: 0px 0px 5px 5px; -moz-border-radius: 0px 0px 5px 5px; -webkit-border-radius: 0px 0px 5px 5px; -o-border-radius: 0px 0px 5px 5px; }
#navigation ul li ul li.first a { border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; -o-border-radius: 0px;}
#navigation ul li.first ul li a { border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; -o-border-radius: 0px;}
And here is how I am trying to write a sub-menu
<nav id="navigation">
<ul>
<li>Individual Patient Analysis</li>
<li>
Multiple Patient Analysis<span></span>
<ul>
<li>Gender</li>
<li>Age</li>
<li>Field Number</li>
<li>Occupation</li>
<li>Eye<span></span>
<ul>
<li>Left</li>
<li>Right</li>
</ul>
</li>
</ul>
</li>
<li>Upload File</li>
</ul>
</nav>
The problem here is the level 2 submenu for eye is always visible, without even hovering on the 'Eye' tab and I just cannot seem to fix it. I want the "Left" and "right" submenu to appear only when one hovers on the "Eye" tab. And another problem that I found in the fiddle is that the menu hides itself on hovering over Left or Right sub menu. How can it be fixed ?
Any help would be much appreciated !
You are hiding the dropdown menu initially using display:none and try to use visibility:visible on hover of the li item which doesn't shows the dropdown menu at all.
Change this
#navigation ul li:hover ul {
visibility: visible;
}
to below to display only the immediate child ul items of the parent li item.
#navigation li:hover > ul {
display:block;
}
DEMO
Check this, It may help you.
DEMO
CSS
ul, ul li {
list-style-type:none;
float:left;
padding:5px;
}
ul li a {
text-decoration:none;
}
li ul {
display:none;
position:absolute;
}
li ul li {
float:none;
}
ul li:hover ul {
display:block;
}
ul li:hover ul ul {
display:none;
}
ul li ul li:last-child:hover ul {
display:block;
}
http://jsfiddle.net/ZhWkP/10/
http://jsfiddle.net/ZhWkP/10/show
You used display:none to hide the second level ul and than use visibility set to visible on hover.
/* apply a natural box layout model to all elements */
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#navigation ul ul ul {
float: none;
line-height: 28px;
position: absolute;
visibility: hidden;
width: 100%;
padding: 0 0 0 10px; /* allows to set padding to 100% element. */
}
#navigation ul ul li:hover ul {
visibility: visible;
}

Glow behind the navigation menu

I am creating a little animation with glow in navigation.
Glow is behind the navigation menu as seen in picture.
I tried but not clear result, I need same result as shown in picture.
http://jsfiddle.net/naresh_kumar/GCpDW/5/
HTML
<div id="topnav" style="float:right;">
<ul class="nav clearfix">
<li id="menu-item-6">
Home
</li>
<li id="menu-item-8">
<a>Tutor Videos</a>
</li>
<li id="menu-item-7">
<a>Download Font</a>
</li>
<li id="menu-item-9">
<a>news</a>
</li>
</ul>
</div>
CSS
body{background:#000000;}
ul { margin-left: 20px; padding: 0; }
#topnav {
font-size: 8pt;
font-weight: bold;
margin-top: 2%;
float: left;
font-size: 8pt;
margin-bottom: 0;
margin-left: 63px;
margin-right: 0;
margin-top: 4% !important;
padding: 0;
width: 60%;
}
#topnav ul {
background: none repeat scroll 0 0 #E2E2DE;
border: 3px solid #FFFFFF;
line-height: 1;
list-style: none outside none;
margin: 0;
padding: 0;
}
#topnav ul li {
float: left;
width: auto;
}
#topnav ul li a {
border-bottom: 15px solid transparent;
border-top: 15px solid transparent;
display: block;
line-height: 30px;
margin: -17px 0;
}
#topnav ul a {
color: #000000 !important;
display: block;
line-height: 24px;
padding: 5px 10px;
position: relative;
text-decoration: none;
z-index: 90;
}
#topnav ul a:hover, #topnav ul ul a:hover {
border-color: white;
color: #0A0A0A;
box-shadow: 0 0 50px gold, 0 0 150px gold;
}
.clearfix:after, blockquote:after {
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
.clearfix, blockquote {
display: block;
}
.clearfix, blockquote {
display: inline-block;
}
It's going to be difficult to get the glow 'behind' the menu just using CSS3 but with some minor tweaks (including more subtle use of colour for the glow) you can make the example you have already produced look quite reasonable with the glow on top of the menu
#topnav ul a:hover, #topnav ul ul a:hover {
border-color: white;
color: #0A0A0A;
box-shadow: 0 0 100px #ffffee, 0 0 100px #ffffee;
}

Pure html css menu with horizontal submenu. Hover not working properly in IE

Iam working on a pure html/css menu with horizontal submenu, but the hover is not working properly in Internet Explorer. When you hover over the submenu it disappears...
In Chrome and Firefox everything works fine.
Here is a jfiddle:
http://jsfiddle.net/te5AU/2/
And here is the code:
<div class="wrapper">
<div class="menu-holder">
<ul class="menu">
<li>item 1
</li>
<li class="active"><a class="test" href="#">This is the one</a>
<ul class="submenu">
<li>Submenu item 1
</li>
<li>Submenu item 2
</li>
</ul>
</li>
<li>menu item 3
</li>
<li>menu item 4
</li>
</ul>
</div>
<!-- menu-holder end -->
</div>
Here is the css:
.wrapper {
width:500px;
height:500px;
background:grey;
}
.menu-holder ul {
margin: 2px 0 0px 25px;
padding: 0;
list-style-type: none;
}
.menu-holder ul li {
position: relative;
float: left;
padding: 0px 10px 0 10px;
margin: 0px 0px 100px 0px;
border-left: 1px dotted white;
line-height: 0px;
}
.menu-holder ul li:hover > a {
background-color: #025179;
}
.menu-holder ul li:hover ul {
display: block;
}
.menu-holder ul li a {
font-family: arial, sans-serif;
font-size: 12px;
font-weight: bold;
display: block;
color: white;
text-decoration: none;
padding: 15px 10px 15px 10px;
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
}
.menu-holder ul li ul {
float: none;
display: none;
position: absolute;
top: 40px;
left: 0px;
margin: -1px 0 0px 10px;
padding: 5px 10px 5px 10px;
white-space: nowrap;
}
.menu-holder ul li ul:hover {
display: block;
}
.menu-holder ul li ul li {
position: static;
float: none;
display: inline;
padding: 5px 10px 5px 10px;
margin: 0px 0px 0px -10px;
background-color: #025179;
}
.menu-holder ul li ul li a {
display: inline;
margin: 0 0px 0 0px;
padding: 0px 10px 0px 10px;
font-weight: normal;
-webkit-border-radius: 0;
border-radius: 0;
}
.menu-holder ul li ul li:first-of-type {
-webkit-border-radius: 0px 0px 0px 5px;
border-radius: 0px 0px 0px 5px;
}
.menu-holder ul li ul li:last-of-type {
-webkit-border-radius: 0px 5px 5px 0px;
border-radius: 0px 5px 5px 0px;
}
.menu-holder ul li:first-of-type {
border-left: none;
}
li is not getting proper height in IE. U should remove
.menu-holder ul li { line-height: 0} //remove the css line-height: 0;
and then try.
Try this:
http://jsfiddle.net/te5AU/4/
HI i have some changing in you css
.menu-holder > ul > li:hover > a {
background-color: #025179;
}
.menu-holder ul li ul {
float: none;
display: none;
position: absolute;
margin:0; top: 30px;padding:0;
left: 10;
white-space: nowrap;font-size:0;
}
.menu-holder ul li ul li {
position: static;
float: none;
display: inline-block;
padding:0;
margin:0px;font-size:14px;
background-color: #025179;
}
.menu-holder ul li ul li a {
display:block;
margin: 0 0px 0 0px;
padding: 0 10px;
line-height:30px;
font-weight: normal;
-webkit-border-radius: 0;
border-radius: 0;
}
Demo