I need a submenu behind the parent menu. Check out the pic (left is the default browser rendering if I'm working with absolute divs, but I need it like on the right):
http://i67.tinypic.com/2nuqb89.jpg
The submenus should be behind the parent menu, to avoid an overlap. I tried some z-index stuff but it doesnt realy work. Like an z-index: -1 might fix the problem for the first submenu, but not for the second, right?
Maybe this fiddle makes it clearer:
html, body {
height: 100%;
background: darkred;
padding: 0;
margin: 0;
}
ul, li {
list-style: none;
margin: 0;
padding: 0;
}
a {
display: block;
color: darkred;
text-decoration: none;
padding: 1rem 2rem;
}
.mainmenu {
width: 10rem;
background: white;
position: fixed;
height: 100%;
z-index: 99;
}
.mainmenu li:hover > ul {
left: 100%;
}
.mainmenu__sub {
width: 10rem;
position: absolute;
left: 0;
top: 0;
z-index: -2;
transition: all 0.3s ease-in-out;
}
.mainmenu__sub--red {
background: red;
}
.mainmenu__sub--green {
background: green;
}
<ul class="mainmenu">
<li>Menu1
<ul class="mainmenu__sub mainmenu__sub--red">
<li>Submenu1
<ul class="mainmenu__sub mainmenu__sub--green">
<li>Subsubmenu1</li>
<li>Subsubmenu2</li>
<li>Subsubmenu3</li>
</ul>
</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
<li>Menu2</li>
<li>Menu3</li>
<li>Menu4</li>
</ul>
tldr; I need to reverse the child/parent z-index behavior
Add same color in instant nested li as per below code.
html, body {
height: 100%;
background: darkred;
padding: 0;
margin: 0;
}
ul, li {
list-style: none;
margin: 0;
padding: 0;
}
a {
display: block;
color: darkred;
text-decoration: none;
padding: 1rem 2rem;
}
.mainmenu {
width: 10rem;
background: white;
position: fixed;
height: 100%;
z-index: 99;
}
.mainmenu > li{
background: white;
}
.mainmenu li:hover > ul {
left: 100%;
}
.mainmenu__sub {
width: 10rem;
position: absolute;
left: 0;
top: 0;
z-index: -2;
transition: all 0.3s ease-in-out;
}
.mainmenu__sub--red, .mainmenu__sub--red > li {
background: red;
}
.mainmenu__sub--green, .mainmenu__sub--green > li {
background: green;
}
<ul class="mainmenu">
<li>Menu1
<ul class="mainmenu__sub mainmenu__sub--red">
<li>Submenu1
<ul class="mainmenu__sub mainmenu__sub--green">
<li>Subsubmenu1</li>
<li>Subsubmenu2</li>
<li>Subsubmenu3</li>
</ul>
</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
<li>Menu2</li>
<li>Menu3</li>
<li>Menu4</li>
</ul>
Related
I want to make a tab style so the bottom of the tab doesn't have an underline. To do this I thought I could set bottom border color of tab and then make child menu go underneath.
I am not sure if that is possible though.
This excerpt is taken from site, it is done like this as the child menu is usually shown on hover.
body {
background-color: #000;
}
.desktop-menu {
color: #fff;
list-style: none;
}
.desktop-menu a {
color: #fff;
text-decoration: none;
}
.desktop-menu > li {
background-color: blue;
width: 60px;
margin-left: 25px;
border: 1px solid #fff;
border-bottom-color: blue;
padding: 10px;
position: relative;
z-index: 20;
}
.desktop-menu ul {
background-color: blue;
z-index: 10;
width: 200px;
display: flex;
position: absolute;
top: 100%;
left: -1px;
flex-direction: column;
list-style: none;
margin: 0;
padding: 10px 20px;
padding-top: 15px;
border: 1px solid #fff;
background-color: darkblue li;
padding-bottom: 15px;
}
.desktop-menu .has-sub:hover {
border: 1px solid #fff;
}
.desktop-menu .has-sub:hover ul {
display: flex;
}
<ul class="desktop-menu">
<li class="has-sub">Products
<ul>
<li>Product name 1</li>
<li>Prod name 2</li>
</ul>
</li>
</ul>
I am trying to remove this white line:
What is best method to achieve this?
Just a hack but it works.
.desktop-menu > li {
position: relative;
// ...
}
.desktop-menu > li::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 1px;
width: 100%;
background-color: blue;
}
.desktop-menu ul {
display: none;
transform: translateY(-1px);
// ...
}
.desktop-menu .has-sub:hover ul {
display: flex;
}
See result in codesandbox.
Note: not suitable if you are working with transparent backgrounds.
Edit: updated the sandbox to proof it works with the hover effect.
I have a menu containing of ul li items. I have five items, using flexbox to align them with the last item using margin-left:auto; to push it to the right.
I am also using transform: skewX(45deg) to create arrows for each li::before and li::after and I have a starting background-color. The arrow border is set to yellow.
My problem is that I would like to individually set the color for each li item, except the last li.
So, I would like to use li:nt-child property and set the background color and also take into account for before and after values.
I am guessing I need also to use the z-index maybe so the previous before and after color values are handled in a proper way.
This is my html code:
<nav class="flex-nav" id="nav">
<ul>
<li>Home page</li>
<li>Test page</li>
<li>Link1</li>
<li>Link2</li>
<li>Login</li>
</ul>
</nav>
And this is my css:
.flex-nav ul {
display: flex;
list-style-type: none;
padding-left: 0;
white-space: nowrap;
}
.flex-nav ul li {
justify-content: space-between;
align-items: center;
opacity: 1.0;
transition: opacity .2s ease-in-out;
position: relative;
line-height: 26px;
margin: 0 9px 0 -10px;
padding: 0 20px;
}
ul li::before,
ul li::after {
border-right: 4px solid yellow;
content: '';
display: block;
height: 50%;
position: absolute;
left: 0;
right: 0;
top: 0;
z-index: -1;
transform: skewX(45deg);
background-color: #b0e0e6;
}
ul li::after {
bottom: 0;
top: auto;
transform: skewX(-45deg);
}
ul li:last-of-type::before,
ul li:last-of-type::after {
display: none;
}
ul li a {
font: bold 18px Sans-Serif;
letter-spacing: -1px;
text-decoration: none;
}
ul>li:hover {
opacity: 1.0;
}
ul:hover>li:not(:hover) {
opacity: 0.5;
}
.flex-nav ul li:last-child {
margin-left: auto;
}
Thanks :)
Try below CSS for change the background color for first, second and third items. Thanks
.flex-nav ul {
display: flex;
list-style-type: none;
padding-left: 0;
white-space: nowrap;
}
.flex-nav ul li {
justify-content: space-between;
align-items: center;
opacity: 1.0;
transition: opacity .2s ease-in-out;
position: relative;
line-height: 26px;
margin: 0 9px 0 -10px;
padding: 0 20px;
}
.flex-nav li:before,
.flex-nav li:after {
border-right: 4px solid yellow;
content: '';
display: block;
height: 50%;
position: absolute;
left: 0;
right: 0;
top: 0;
z-index: -1;
transform: skewX(45deg);
}
.flex-nav li:first-child::before,
.flex-nav li:first-child::after {
background-color: red;
}
.flex-nav li:nth-child(2)::before,
.flex-nav li:nth-child(2)::after {
background-color: green;
}
.flex-nav li:nth-child(3)::before,
.flex-nav li:nth-child(3)::after {
background-color: blue;
}
<nav class="flex-nav" id="nav">
<ul>
<li>Home page</li>
<li>Test page</li>
<li>Link1</li>
<li>Link2</li>
<li>Login</li>
</ul>
</nav>
I have problem with my drop-down menu. I don't know how to change position of buttons after scrolling under line to center position. Could you help me please?Thanks!
Example:
enter image description here
* {margin: 0; padding: 0;}
body {
font-family: arial;
color:#ccc;
}
#full-screen-background-image {
z-index: -999;
min-height: absolute;
min-width: absolute;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
#wrapper {
min-height: 100%; _height: 100;
margin: 0 auto -150px auto;
}
a:hover {
color: #0095cd;
}
section {
background: url(/Users/ivanazuskinova/Dropbox/auttalk/INDEX/menu01.png)50% 0 no-repeat;
background-size: 1900px 86px;
opacity:0.8;
}
#header-content {
width:960px;
margin: 0 auto;
padding: 60px 0;
}
#content {
width: 960px;
margin: 0 auto;
padding: 100px 0;
}
.static {
width: 960px;
margin: 0 auto;
text-align: center;
position: relative;
}
nav li{
display: inline-block;
padding: 35px 60px 100px 0px;
}
nav li:nth-child(3) {
padding-right: 200px;
}
nav li:nth-child(1) {
padding-left: 4in 0px;
}
.static a {
transition: all linear 0.15s;
color: white;
}
.static li:hover > a,
.static .current-item > a {
text-decoration: none;
color: white;
}
.static .highlighted {
font-size: 10px;
line-height: 0%;
}
.static li:hover .dynamic {
z-index: 10;
opacity: 1;
}
.dynamic {
position: absolute;
z-index: 0;
opacity: 0;
transition: opacity linear 0.15s;
background: #ccc;
}
.dynamic li {
display: relative;
font-size: 14px;
}
.dynamic li a {
text-decoration: none;
color:#17177e;
}
.logo {
background: url(/Users/ivanazuskinova/Dropbox/auttalk/INDEX/logo.png) 50% 0 no-repeat;
background-size: 125px 86px;
height:155px;
width:180px;
position: absolute;
top: 2px;
left: 390px;
}
<section>
<header>
<div id="wrapper">
<div id="header">
<div class="static-wrap">
<div class="static">
<nav>
<ul>
<li>Home</li>
<li>o vás
<ul class="dynamic">
<li> <span class="highlighted">►</span>Vaše přiběhy</li>
<li><span class="highlighted">►</span>Diskusní fórum
</li>
</ul>
</li>
<li>Services</li>
<li>Work</li>
<li>Blog</li>
<li>Kontakt</li>
</ul>
</nav>
<div class="logo"></div>
</header>
</section>
Try adding a block display to the li links.
.dynamic li a {
display: block;
text-decoration: none;
color:#17177e;
}
Your
.dynamic li {
display: relative;
font-size: 14px;
}
add in 'display: block' in here so it looks like...
.dynamic li {
display: block;
font-size: 14px;
}
so I'm having this issue. Here is the jsfiddle.
https://jsfiddle.net/g5yo9jts/
<body>
<div class="header">
<div class="menuIcon">
<a id="nav-toggle" href="#menuExpand"><span></span></a>
<div class="box"><h3>Home</h3></div>
</div>
<div class="menu">
<ul>
<li>Menu Option 1</li>
<li>Menu Option 2</li>
<li>Menu Option 3</li>
<li>Menu Option 4</li>
</ul>
</div>
</div>
</body>
* {
-webkit-font-smoothing:antialiased;
padding: 0;
margin: 0;
}
#nav-toggle span {
margin-left: 15px;
float: left;
}
#nav-toggle span, #nav-toggle span:before, #nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 3px;
width: 25px;
background: white;
position: absolute;
display: block;
content: '';
}
#nav-toggle span:before {
top: -6px;
}
#nav-toggle span:after {
bottom: -6px;
}
#nav-toggle span, #nav-toggle span:before, #nav-toggle span:after {
transition: all 500ms ease-in-out;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
h3 {
font-size: 1em;
color: white;
float: right;
margin-right: 15px;
margin-bottom: 25px;
font-family: "alternate-gothic-no-3-d";
font-weight: 800;
}
.header .menu ul {
padding: 0;
margin: 0;
}
.header .menu ul li {
display: inline-block;
list-style: none;
padding: 0 0 0 5px;
margin: 0;
}
.header .menuIcon {
height: 50px;
display: none;
background: #000;
width: 100%;
}
.header .menuIcon a {
width: 100%;
display: inline-block;
color: #fff;
}
.header .menuIcon a img {
vertical-align: middle;
}
#media only screen and (min-width: 400px) {
.menu {
display: none;
}
}
#media only screen and (max-width: 767px) {
.header .menu {
max-height: 0;
overflow: hidden;
float: none;
text-align: center;
width: 100%;
-webkit-transition: max-height 0.5s;
-moz-transition: max-height 0.5s;
transition: max-height 0.5s;
}
.header .menu.menuOpen {
max-height: 1000px;
-webkit-transition: max-height 0.5s;
-moz-transition: max-height 0.5s;
transition: max-height 0.5s;
}
.header .menu ul li {
display: block;
width: 100%;
background: #000;
border-top: 1px solid #4d4d4d;
}
.header .menu ul li:hover {
background: #999;
}
.header .menu ul li a {
color: #fff;
text-shadow: #848484 0px 1px 2px;
padding: 10px;
width: 100%;
}
.header .menuIcon {
display: inline-block;
}
}
$(function() { $("a[href=#menuExpand]").click(function(e) {
$(".menu").toggleClass("menuOpen"); e.preventDefault(); });});
document.querySelector( "#nav-toggle" ).addEventListener( "click",
function(){
this.classList.toggle( "active" );
});
$(".header").click(function() {
$('.menu').show();
});
The main issue is my hamburger icon and text font aren't lining up. As you can see the hamburger is centered vertically and the text is on bottom right. I've tried everything from margining the text, to adding a box div to the text to move it. Floating, absolute positioning is not working.
I'd also like to have the hamburger icon on the right, and the text for my page on the left but I was having issues with the centering that I hadn't got that far. If anybody could help out that would be awesome.
Thanks so much.
NB: Resize the fiddle 'Result' view to something closer to a mobile/tablet device display resolution to view the menu. Maximum width 767px.
I think i have your problem solved. Only thing is there is a small gap between the header and the menu items when the menu appears (didn't tackle that) I'm sure some negative padding/margin will fix that right up
$(function() {
$("a[href=#menuExpand]").click(function(e) {
$(".menu").toggleClass("menuOpen");
e.preventDefault();
});
});
document.querySelector("#nav-toggle").addEventListener("click", function() {
this.classList.toggle("active");
});
$(".header").click(function() {
$('.menu').show();
});
$(".swap").click(function() {
var _this = $(this);
var current = _this.attr("src");
var swap = _this.attr("data-swap");
_this.attr('src', swap).attr("data-swap", current);
});
* {
-webkit-font-smoothing: antialiased;
padding: 0;
margin: 0;
}
.menuIcon a,
.menuIcon p {
display: inline;
}
#nav-toggle span {
margin-left: 15px;
float: left;
}
#nav-toggle span,
#nav-toggle span:before,
#nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 3px;
width: 25px;
background: #000000;
position: absolute;
display: block;
content: '';
}
/*#nav-toggle span:before {
top: -6px;
}
#nav-toggle span:after {
bottom: -6px;
}*/
#nav-toggle img,
#nav-toggle img:before,
#nav-toggle img:after {
transition: all 500ms ease-in-out;
}
#nav-toggle.active img:before,
#nav-toggle.active img:after {
top: 0;
}
#nav-toggle.active img:before {
transform: rotate(45deg);
}
#nav-toggle.active img:after {
transform: rotate(-45deg);
}
h3 {
font-size: 1em;
color: white;
float: left;
margin-left: 15px;
padding-top: 15px;
font-family: "alternate-gothic-no-3-d";
font-weight: 800;
}
.header .menu ul {
padding: 0;
margin: 0;
}
.header .menu ul li {
display: inline-block;
list-style: none;
padding: 0 0 0 5px;
margin: 0;
}
.header .menuIcon {
height: 50px;
display: none;
background: #000;
width: 100%;
}
.header .menuIcon a {
width: 100%;
display: inline-block;
color: #fff;
}
.header .menuIcon a img {
width: 75px;
height: 50px;
float: right;
margin-top: -34px;
margin-bottom: 15px;
}
#media only screen and (min-width: 400px) {
.menu {
display: none;
}
}
#media only screen and (max-width: 767px) {
.header .menu {
max-height: 0;
overflow: hidden;
float: none;
text-align: center;
width: 100%;
-webkit-transition: max-height 0.5s;
-moz-transition: max-height 0.5s;
transition: max-height 0.5s;
}
.header .menu.menuOpen {
max-height: 1000px;
-webkit-transition: max-height 0.5s;
-moz-transition: max-height 0.5s;
transition: max-height 0.5s;
}
.header .menu ul li {
display: block;
width: 100%;
background: #000;
border-top: 1px solid #4d4d4d;
}
.header .menu ul li:hover {
background: #999;
}
.header .menu ul li a {
color: #fff;
text-shadow: #848484 0px 1px 2px;
padding: 10px;
width: 100%;
}
.header .menuIcon {
display: inline-block;
}
}
<body>
<div class="header">
<div class="menuIcon">
<p>
<h3>ELIJi</h3>
</p>
<a id="nav-toggle" href="#menuExpand">
<img class="swap" src="http://www.rachelgallen.com/images/hamburgerIcon.png" data-swap="http://www.rachelgallen.com/images/close.png"></img>
</a>
</div>
<div class="menu">
<ul>
<li>Menu Option 1
</li>
<li>Menu Option 2
</li>
<li>Menu Option 3
</li>
<li>Menu Option 4
</li>
</ul>
</div>
</div>
</body>
I have a problem with hover on this site I'm doing. The menu is ok in all pages, except the home. What is kinda awkward, 'cause I'm just using php include to change the content, and the header, menu and footer are always the same.
In Firefox and Chrome it's ok, but the problem is that when I mouseover the menu on IE9 it has a displacement, like the image:
example
http://i74.photobucket.com/albums/i265/_k_ps_/exemplo.gif
I think it's something with the display: block, but I don't know how to fix it and make the menu work properly :(
Here is the HTML:
<div id="menu" class="group">
<ul>
<li id="menu-01"><span>Home</span></li>
<li id="menu-02"><span>A Empresa</span></li>
<li id="menu-03"><a href="galeria_representacao.php?image=0">
<img src="images/representacao.jpg" class="menu-head" onMouseOver="this.src='images/representacao-hover.jpg'" onMouseOut="this.src='images/representacao.jpg'"></a>
<ul class="menu-body">
<li>Teste1</li>
<li>Teste2</li>
<li>Teste3</li>
<li>Teste4</li>
<li>Teste5</li>
</ul>
</li>
<li id="menu-04"> <span>Serviços</span></li>
<li id="menu-05"><span>Projetos</span></li>
<li id="menu-06"><span>Novidades</span></li>
<li id="menu-07"><span>Contato</span></li>
<li id="menu-08"><span>E-mail</span></li>
<li id="menu-09"><span>Login</span></li>
</ul>
</div>
And the CSS:
#menu {
width: 834px;
height: 44px;
background-image: url(../images/menu-up.jpg);
display: block;
}
#menu ul {
width: 834px;
height: 44px;
list-style: none;
margin: 0;
padding: 0;
float: left;
position: absolute;
}
#menu ul span {
display: none;
}
#menu ul li {
list-style: none;
display: block;
float: left;
position: relative;
}
#menu li ul {
position: absolute;
display: none;
z-index: 12;
}
#menu li ul li {
clear: both;
position: relative;
margin: 0;
padding: 0;
background-color: #0676c4;
width: 157px;
height: 40px;
font-family: Helvetica, Verdana, sans-serif;
font-size: 14px;
}
#menu li ul li a {
clear: both;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
padding: 10px;
margin: 0;
display: block;
}
#menu li ul li a:hover {
background-color: #87c5f1;
height: 20px;
margin: 0;
}
#menu ul li, #menu ul a {
margin: 0;
padding: 0;
text-decoration: none;
height: 44px;
display: block;
}
#menu-01 {
left: 0px;
width: 75px;
}
#menu-01 a:hover {
background-image: url(../images/menu-down.png);
}
#menu-02 {
left: 0px;
width: 112px;
}
#menu-02 a:hover {
background: url(../images/menu-down.png) -75px;
}
#menu-03 {
background-image: url(../images/representacao.jpg);
left: 0px;
width: 157px;
z-index: 11;
border: 0;
}
#menu-04 {
left: 0px;
width: 103px;
}
#menu-04 a:hover {
background: url(../images/menu-down.png) -344px;
}
#menu-05 {
left: 0px;
width: 108px;
}
#menu-05 a:hover {
background: url(../images/menu-down.png) -447px;
}
#menu-06 {
left: 0px;
width: 113px;
}
#menu-06 a:hover {
background: url(../images/menu-down.png) -555px;
}
#menu-07 {
left: 0px;
width: 101px;
}
#menu-07 a:hover {
background: url(../images/menu-down.png) -668px;
}
.menu-head {
border-width: 0;
}
Can somebody help me?
I put your code (and modified it a bit) in a jsfiddle.
The problem, from what I see, seems to be with the 3rd element, which has a child ul.
From what I see from there, you have a problem with your CSS :
This CSS style
#menu ul {
width: 834px;
height: 44px;
list-style: none;
margin: 0;
padding: 0;
float: left;
position: absolute;
}
Affect this HTML element :
<ul class="menu-body">
Which you probably don't want to. (fixed here)
But I'm not sure it's your error, the code you supplied needs the images, and I do not have them...
Also, all your left:0px are useless.
If you want a better answer, you'll have to enhance your question (and/or the jsfiddle!). :-)