http://jsfiddle.net/vxaAE/
I tried to integrate this menu in my project but it comes to me with two problems.
- sub menu going out of window when I have this scenario-
http://jsfiddle.net/vxaAE/
- I tried to give submenu's width to auto, because it would be according to sub menu's length.
How do I get this working?
CSS-
.mega-wrapper {
width: 100%;
margin: 0 auto;
}
.mega-nav {
position: relative;
width: auto;
height: 59px;
background: #252428;
}
.mega-nav ul .mega-ul {
display: block;
margin: 0;
padding: 0;
list-style: 0;
}
.mega-nav .mega-ul li {
position: relative;
display: inline-block;
}
.mega-nav .mega-ul li a {
display: block;
font-size: 1em;
color: #fff;
text-decoration: none;
padding: 0 15px;
}
.mega-nav .mega-ul li a:hover, .mega-nav .mega-ul li:hover > a {
background: #333;
}
.mega-nav .mega-ul li:hover > .mega-div {
display: block;
}
.mega-div {
position: absolute;
top: 100%;
left: 0;
width: 450px;
height: auto;
padding: 20px 30px;
background: #333;
display: none;
z-index:1000;
}
.mega-ul li ul {
float: left;
width: 23%;
margin: 0 2% 15px 0;
padding: 0;
list-style: none;
}
.mega-ul li ul li {
display: block;
}
.mega-ul li ul li a {
float: left;
display: block;
width: 100%;
height: auto;
line-height: 1.3em;
color: #888;
text-decoration: none;
padding: 1px 0;
}
.mega-ul li ul li:first-child a {
font-size: 1.2em;
color: #8dc63f;
}
.mega-ul li ul li a:hover {
color: #fff;
background: none;
}
.mega-ul ul li:first-child a:hover {
color: #fff;
}
/* clearfix */
.mega-nav .mega-ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.mega-nav .mega-ul {
display: inline-block;
}
.header-title {
line-height: 59px;
}
Any help would be greate appreciated.
Fiddle
You can do this:
.mega-nav .mega-ul li:nth-child(1n+6):hover .mega-div{
right:0;
left:auto;
}
This way, starting from the 6th .mega-nav .mega-ul li:nth-child(1n+6):hover .mega-div, it will align to right:0; going the other way.
This is thanks to nth-child(1n+6), which means starting from the 6th element, every one after has this property.
It's not the prettiest alternative, but you can mess around, making it left:-50%, or right:50%.
If you know how many you have and will always be that way and you know what one works where, you can just use :nth-child(n) and style that way. (n being the number in which that element appears).
Remove position relative from li tag
.mega-ul li {
display: inline-block;
position: relative; // remove it
}
http://jsfiddle.net/vxaAE/1/
Related
I seem to be having a problem with my CSS in making the entire menu item clickable, not just the text.
As you can see from the highlighted screenshot, the menu does not extend to 100% height of the div. As a result, only the text of the menu is clickable, not the whole box around it. How do I make the entire box clickable?
(Code Below)
#header
{
background-color: black;
}
#header .menu
{
display: inline;
text-decoration: none;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
height: 100%
position: relative;
text-transform:uppercase;
}
#header .menu ul{
display: inline-block;
}
#header .menu li {
display: inline-block;
padding: 20px;
width: auto;
color: white;
height: 100%;
position: relative;
}
#header .menu a{
display: block;
width: 100%
height: 100%;
text-decoration: none;
color: white;
font-family: Helvetica;
}
#header .menu ul li a{
display: block;
}
#header .menu li a{
position: relative;
}
Thanks.
Use this piece of CSS
#header .menu
{
display: inline;
text-decoration: none;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
height: 100%
position: relative;
text-align: center;
text-transform:uppercase;
}
#header .menu li { display: inline; float:left; }
#header .menu li a
{
text-decoration: none;
padding: .2em 1em;
color: #fff;
background-color: #000;
font-family: Helvetica;
}
#header ul li a:hover
{
color: Yellow;
background-color: #000;
}
Here is a Demo
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 have this css code for my responsive css menu:
nav, ul, li, a {
margin: 0; padding: 0;
}
a {
text-decoration: none;
}
.container {
width: 100%;
margin: 10px auto;
}
.toggleMenu {
display: none;
background: #666;
padding: 10px 15px;
color: #fff;
}
.nav {
list-style: none;
*zoom: 1;
background:#f36f25;
}
.nav:before,.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 9em;
}
.nav a {
padding: 10px 15px;
color:#fff;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-top: 1px solid #104336;
}
.nav > li > .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: right;
}
.nav > li > a {
display: block;
}
.nav li ul {
position: absolute;
left: -9999px;
}
.nav > li.hover > ul {
left: 0;
}
.nav li li.hover ul {
left: 100%;
top: 0;
}
.nav li li a {
display: block;
background: #1d7a62;
position: relative;
z-index:100;
border-top: 1px solid #175e4c;
}
.nav li li li a {
background:#249578;
z-index:200;
border-top: 1px solid #1d7a62;
}
#media screen and (max-width: 768px) {
.active {
display: block;
}
.nav > li {
float: none;
}
.nav > li > .parent {
background-position: 95% 50%;
}
.nav li li .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: 95% 50%;
}
.nav ul {
display: block;
width: 100%;
}
.nav > li.hover > ul , .nav li li.hover ul {
position: static;
}
}
but i cannot get the menu items to align in the centre of the menu/page
here is a fiddle with the full code:
http://jsfiddle.net/5Z2QV/
Is THIS FIDDLE what you want?
If so, then you have to remove float from the lis and add display: inline-block to them. Then you have to add text-align: center to the .nav
.nav {
list-style: none;
background:#f36f25;
text-align: center;
border-top: 1px solid #104336;
}
.nav > li {
display: inline-block;
}
I also removed border-top from the li and put it in the .nav to remove the gaps between lis.
EDIT:
To keep sub-menu items aligned to the left, add this CSS:
.nav li {
text-align: left;
}
EDIT2:
You don't need this adjustMenu() javascript function. You can use media queries. Modify your #media section a bit. Add this style:
.nav {
border-top: none;
}
and replace style for .nav > li with this:
.nav > li {
display: block;
border-top: 1px solid #104336;
}
Also, I noticed that in the small range of resolution, one menu item breaks into new line. To prevent this, you can add this style to the .nav
white-space: nowrap;
overflow: hidden;
Here's the update fiddle: http://jsfiddle.net/5Z2QV/9/
When I set the width of the sub menu to width:auto, the items with really long names gets squished together. Currently I have the width set to 175% which is not desirable as some menus can get quiet long. How can I make width:auto work for long menu items.
Link to demo site: http://previewyournewwebsite.info/otsl/
.nav.main_nav .sub-menu {
background-color: #2D556F;
display: none;
height: auto;
/* left: -5px; */
left: 0px;
margin: 0 9px 0 0;
position: absolute;
top: 54px;
width: 175%;
}
.nav.main_nav .sub-menu li {
margin: 30px 0px;
display: block;
}
.nav.main_nav .sub-menu li a {
background-image: url("./images/sub-nav-divider.png");
background-position: 0 bottom;
height: 50px;
line-height: 50px;
background-repeat: repeat-x;
font-family: Helvetica,Arial,sans-serif;
font-size: 15px;
margin-left: -31px;
padding: 0 0 0 44px;
width: 100%;
}
.nav.main_nav .sub-menu > li{
height: 50px;
line-height: 50px;
padding-left: 44px;
}
.nav.main_nav .sub-menu > li:last-child a{
background-image: none;
}
.nav.main_nav .sub-menu li {
display: block;
margin: 0;
}
Link to site: http://previewyournewwebsite.info/otsl/
Are you looking for this?
http://jsfiddle.net/coma/MNFXB/11/
nav ul, nav li {
list-style: none;
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
nav a {
display: block;
text-decoration: none;
text-transform: uppercase;
padding: 1em;
color: #fff;
background-color: #2D556F;
white-space: nowrap;
}
nav > ul {
background-color: #2D556F;
}
nav > ul:after {
display: block;
content: "";
clear: both;
}
nav > ul > li {
float: left;
position: relative;
}
nav > ul > li > ul {
position: absolute;
top: 100%;
left: 0;
min-width: 100%;
display: none;
}
nav > ul > li:hover > ul {
display: block;
}
nav li:hover > a {
background-color: #92A132;
}
Or would you like something like this?
http://jsfiddle.net/coma/MNFXB/12/
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{}