I've created a vertical menu on the right of page and a not displayed panel (display:none) on the left, next to menu.Now, when I drag the mouse on links of menu (a:hover), the panel on the right should appear, but It doesn't! Why?
HTML:
<div id="menupanel">
<ul>
<li>
PERFORMANCE<img src="images/menu.png" />
<ul>
<li><h2>PERFORMANCE</h2>
<p>Are you an artist working in the field of live audiovisual...</p>
</li>
</ul>
</li>
</ul>
</div>
CSS:
#menupanel{
margin-top:50px;
width:300px;
padding:0 75px;
clean:both;
}
#menupanel h1{
font-size:16px;
color:#FFF;
margin:10px auto;
text-align:center;
}
#menupanel h2{
text-align:center;
padding-top:30px;
color:#FFF;
}
#menupanel ul{
list-style: none;
margin: 0;
width: 300px;
}
#menupanel ul li a{
display: block;
margin: 0;
padding: 0 3px;
text-decoration: none;
color: #FFF;
background:#05c597;
height:54px;
text-align:center;
line-height:54px;
}
#menupanel ul>li a:hover {
color: #FFF;
background: #3c4c55;
}
#menupanel li {
position:relative;
background:#05c597;
margin-bottom:15px;
}
#menupanel ul li img{
position:relative;
top:5.8px;
height:46%;
right:0px;
transition:0.5s;
-webkit-transition:0.5s;
-moz-transition:0.5s;
}
#menupanel ul li a:hover img{
right:-50px;
}
#menupanel ul li ul{
position: absolute;
top: -10px;
left: 100%;
width: 916px;
display:none;
height:350px;
}
#menupanel ul li ul li{
height:350px;
background: #3c4c55;
top:10px;
}
#menupanel ul li a:hover ul{
display:block;
}
What you're doing in your code right now using #menupanel ul li a:hover ul is trying to target any list that are children of your link element. The list you're trying to target is however not a child but a sibling to your link element.
You can either use the + selector to target the sibling.
#menupanel ul li a:hover + ul{display:block;}
or you can put the hover state on the list element instead.
#menupanel ul li:hover ul{display:block;}
Either one will work
Fiddle
#menupanel{
margin-top:50px;
width:300px;
padding:0 75px;
clean:both;
}
#menupanel h1{
font-size:16px;
color:#FFF;
margin:10px auto;
text-align:center;
}
#menupanel h2{
text-align:center;
padding-top:30px;
color:#FFF;
}
#menupanel ul{
list-style: none;
margin: 0;
width: 300px;
}
#menupanel ul li a{
display: block;
margin: 0;
padding: 0 3px;
text-decoration: none;
color: #FFF;
background:#05c597;
height:54px;
text-align:center;
line-height:54px;
}
#menupanel ul>li a:hover {
color: #FFF;
background: #3c4c55;
}
#menupanel li {
position:relative;
background:#05c597;
margin-bottom:15px;
}
#menupanel ul li img{
position:relative;
top:5.8px;
height:46%;
right:0px;
transition:0.5s;
-webkit-transition:0.5s;
-moz-transition:0.5s;
}
#menupanel ul li a:hover img{
right:-50px;
}
#menupanel ul li ul{
position: absolute;
top: -10px;
left: 100%;
width: 916px;
display:none;
height:350px;
}
#menupanel ul li ul li{
height:350px;
background: #3c4c55;
top:10px;
}
#menupanel ul li:hover ul{
display:block;
}
<div id="menupanel">
<ul>
<li>
PERFORMANCE<img src="images/menu.png" />
<ul>
<li><h2>PERFORMANCE</h2>
<p>Are you an artist working in the field of live audiovisual...</p>
</li>
</ul>
</li>
</ul>
</div>
The <ul> is not a child of , it's a sibling.
So instead of
#menupanel ul li a:hover ul {
display:block;
}
use the adjacent sibling selector +
#menupanel ul li a:hover+ul {
display:block;
}
The <ul> is a sibling of the <a>, not a child. Try:
#menupanel ul>li a:hover~ul {display:block}
Replace :
#menupanel ul li a:hover ul{
display:block;
}
With this :
#menupanel ul li a:hover + ul{
display:block;
}
read more : http://css-tricks.com/child-and-sibling-selectors/
Related
I am creating a page where there is a menu that contains a submenu centered at the top of the page, my problem is being to centralize the submenu with the main menu, because it always goes out of alignment, does anyone know what it can be? Thank you in advance for any help!
"ps:in the image contains the visible error"
edit1:run and with the link and with the html that was missing.
link:https://testtestteste111111.000webhostapp.com/
.menu{
width:100%;
height:49px;
background-color:#494545;
font-family:'Arial';
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
z-index:9999;
}
.menu ul{
list-style:none;
position:relative;
margin-left:24%;
}
.menu ul li{
width:150px;
float:left;
}
.menu a{
padding:15px;
display:block;
text-decoration:none;
text-align:center;
background-color:#494545;
color:#fff;
}
.menu ul ul{
position:absolute;
visibility:hidden;
}
.menu ul li:hover > ul{
visibility:visible;
/* border:1px solid #901E93; sub div*/
}
.menu a:hover{
background-color:#7F818D;
color:#fff;
}
.menu ul ul li{
float:none;
border-bottom:solid 1px #ccc;
margin-left:-164%;
}
.menu ul ul li a{
background-color:#646464;
}
label[for ="bt_menu"]{
padding:5px;
background-color:#494545;
color:#fff;
font-family:"Arial";
text-aling:center;
font-size:30px;
cursor:pointer;
width:100%;
max-height:58px;
z-index:9999;
margin-top:-10px;
top:-5px;
display:none;
position:fixed;
}
.imgbar{
max-height:25px;
max-width:25px;
margin-top:10px;
}
#bt_menu{
display:none;
}
#media(max-width:800px){
label[for="bt_menu"]{
display:block;
color:#fff;
z-index:9999;
position:fixed;
margin-top:1px;
}
.menu{
margin-top:-1px;
margin-left:-100%;
transition:all .4s}
#bt_menu:checked ~ .menu{
margin-left:0;}
.menu ul li{
width:100%;
float:none;}
.menu ul ul{
position:static;
overflow:hidden;
max-height:0;
transition:all .4s;
}
.menu ul li:hover ul{
height:auto;
max-height:200px;
}
.menu ul{
list-style:none;
position:relative;
margin-left:0;
z-index:9999;
}
.menu ul ul li{
float:none;
border-bottom:solid 1px #ccc;
margin-left:0;
}
.parallax {
width:100%;
/* The image used */
background-image: url(../img/img1.jpg);
/* Set a specific height */
height: 800px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin-top:-50px;
}
#ultopo{
margin-top:49px;
}}
html
<input type="checkbox" id="bt_menu">
<label for="bt_menu"><img class="imgbar" src="img/bars.svg"></img></label>
<nav class="menu">
<ul id="ultopo">
<li>Home</li>
<li>Serviços
<!-- nested UL in LI -->
<ul>
<li>ex:A</li>
<li>ex:b</li>
</ul>
</li>
<li>Atuaçao
<!-- nested UL in LI -->
<ul>
<li>ex:A</li>
<li>ex:B</li>
<li>ex:C</li>
</ul>
</li>
<li>contato</li>
</ul>
</nav>
Please update css
Here is link https://jsfiddle.net/jbv09vy4/1/
Add css
.menu ul li {
position: relative;
}
.menu ul ul {
left: 0;
margin: 0;
}
and remove styles margin-left: -164% from
.menu ul ul li {
float: none;
border-bottom: solid 1px #ccc;
margin-left: -164%;
}
I'm currently working on my website and I have an existing navigation bar. The problem is that I have too much information to share on one page. That's why I'd like to implement a dropdown menu in the existing navigation bar. I've tried many many things but it all seems to screw up my lay-out of the css or it completely deletes the navigation bar.
I got an exisiting code for a dropdown menu but I simply am not able to blend it with the existing css code. I got this code from the internet, it is not my property.
My HTML:
<div id="menu">
<ul>
<li class="current_page_item">Home</li>
<li>Onze service</li>
<li>Ons team</li>
<li>Prijzen</li>
<li>Contact</li>
</ul>
</div>
My CSS:
#menu
{
position: absolute;
right: 0;
top: 1em;
}
#menu ul
{
display: inline-block;
}
#menu li
{
display: block;
float: left;
text-align: center;
line-height: 60px;
}
#menu li a, #menu li span
{
display: inline-block;
margin-left: 1px;
padding: 0em 1.5em;
letter-spacing: 0.10em;
text-decoration: none;
font-size: 1.0em;
text-transform: uppercase;
outline: 0;
color: #212121;
background: #ECECEC;
}
#menu li:hover a, #menu li.active a, #menu li.active span
{
}
#menu .current_page_item a
{
background: #E24E2A;
color: #FFF;
}
#menu .icon
{
}
Drop down menu:
#primary_nav_wrap
{
margin-top:15px
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
#primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
#primary_nav_wrap ul li:hover
{
background:#f6f6f6
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary_nav_wrap ul ul li
{
float:none;
width:200px
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
#primary_nav_wrap ul li:hover > ul
{
display:block
}
Thanks in advance!
Your navigation wrapper is menu whereas in the CSS from online it is primary_nav_wrap, so swap instances of these to menu.
In the html itself nested unordered list elements is used for the drop-downs, so add these under the list element where you need a drop-down.
Html:
<div id="menu">
<ul>
<li class="current_page_item">Home<ul>
<li>sub1</li>
<li>sub2</li>
<li>sub3</li>
</ul>
<li>Onze service</li>
<li>Ons team</li>
<li>Prijzen</li>
<li>Contact</li>
</ul>
</div>
CSS:
#menu ul {
display:inline-block;
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
#menu li {
display:block;
float:left;
text-align:center;
line-height:60px
}
#menu li a,#menu li span {
display:inline-block;
margin-left:1px;
padding:0 1.5em;
letter-spacing:.1em;
text-decoration:none;
font-size:1em;
text-transform:uppercase;
outline:0;
color:#212121;
background:#ECECEC
}
#menu .current_page_item a {
background:#E24E2A;
color:#FFF
}
#menu {
margin-top:15px
}
#menu ul a {
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#menu ul li {
position:relative;
float:left;
margin:0;
padding:0
}
#menu ul li.current-menu-item {
background:#ddd
}
#menu ul li:hover {
background:#f6f6f6
}
#menu ul ul {
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#menu ul ul li {
float:none;
width:200px
}
#menu ul ul a {
line-height:120%;
padding:10px 15px
}
#menu ul ul ul {
top:0;
left:100%
}
#menu ul li:hover > ul {
display:block
}
Here is a jsfiddle of the code merged:
https://jsfiddle.net/o51pp5s6/
i have this css:
.vertical-nav {
height:35px;;
list-style:none;
width: 100%; /******* MODIFIED ********/
margin-top:0;
margin-bottom:35px;
padding:0;
background:#03F;
}
.vertical-nav li {
height: 25px;
margin: 0;
text-align:center;
padding: 5px 0;
background-color: #03F;
border: none;
display: inline-block;
float: left;
width: 120px; /******* MODIFIED ********/
}
.vertical-nav li:hover {
background-color:#000000;
color:#FFFFFF;
}
.vertical-nav li a {
font-family:Calibri, Arial;
font-size:18px;
font-weight:bold;
color:#ffffff;
text-decoration:none;
}
.vertical-nav li.current {
background-color:#000000;
}
.vertical-nav li.current a {
color:#FFFFFF;
}
vertical-nav ul li ul {
display:none;
list-style-type:none;
width:125px;
padding:0px;
margin-top:3px;
margin-left:-5px;
}
vertical-nav ul li:hover ul {
display:block;
}
vertical-nav ul li:hover ul li {
background-color:#555555;
width:125px;
height:30px;
display:inline-block;
}
vertical-nav ul li ul li:hover {
background-color:#333333;
}
vertical-nav ul li ul li a {
color:#FFF;
text-decoration:underline;
}
vertical-nav ul li ul li a:hover {
text-decoration:none;
}
.vertical-nav li ul {
display: none;
margin-top: 10px;
padding: 0;
}
.vertical-nav li:hover ul {
display: block;
}
.vertical-nav li:hover .sub-menu
{
display: table;
}
.sub-menu li
{
width: 100%;
min-width: 180px;
white-space: nowrap;
display:table-row;
z-index:1;
position:relative;
}
.sub-menu li a
{
display:inline-block;
padding: 0 10px;
}
the menu is 100% width of the page so i need to get the links centred in the page
here is a jsFiddle so you can see the HTML Too and the fully functional menu: http://jsfiddle.net/rspc3/
Move the text-align:center; rule from .vertical-nav li to .vertical-nav and remove the float: left; on .vertical-nav li
jsFiddle example
this will work perfectly
<ul id="nav">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
#nav{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
}
#nav li{
display:inline;
}
#nav a{
display:inline-block;
padding:10px;
}
Replace your CSS with:
.vertical-nav {
height:35px;;
list-style:none;
width: 100%; /******* MODIFIED ********/
margin-top:0;
margin-bottom:35px;
padding:0;
background:#03F;
text-align:center;
padding-top:10px;
}
.vertical-nav li {
height: 25px;
margin: 0;
text-align:center;
padding: 5px 0;
background-color: #03F;
border: none;
display: inline;
float: none;
margin:0px 30px 0px 0px;
width: 120px; /******* MODIFIED ********/
}
.vertical-nav li:hover {
background-color:#000000;
color:#FFFFFF;
}
.vertical-nav li a {
font-family:Calibri, Arial;
font-size:18px;
font-weight:bold;
color:#ffffff;
text-decoration:none;
}
.vertical-nav li.current {
background-color:#000000;
}
.vertical-nav li.current a {
color:#FFFFFF;
}
vertical-nav ul li ul {
display:none;
list-style-type:none;
width:125px;
padding:0px;
margin-top:3px;
margin-left:-5px;
}
vertical-nav ul li:hover ul {
display:block;
}
vertical-nav ul li:hover ul li {
background-color:#555555;
width:125px;
height:30px;
display:inline-block;
}
vertical-nav ul li ul li:hover {
background-color:#333333;
}
vertical-nav ul li ul li a {
color:#FFF;
text-decoration:underline;
}
vertical-nav ul li ul li a:hover {
text-decoration:none;
}
.vertical-nav li ul {
display: none;
margin-top: 10px;
padding: 0;
}
.vertical-nav li:hover ul {
display: block;
}
.vertical-nav li:hover .sub-menu
{
display: table;
}
.sub-menu li
{
width: 100%;
min-width: 180px;
white-space: nowrap;
display:table-row;
z-index:1;
position:relative;
}
.sub-menu li a
{
display:inline-block;
padding: 0 10px;
}
Hi I cannot figure out how to change the size of the child item of the CSS menu (The parent has an image background, the child should have a background color).
I tried something like:
ul > li > a:hover {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
but it is all mixed with other elements. Can you please help me figure it out?
HTML:
<div id="menu">
<ul>
<li><a id="menu1" href="#">Parent1</a></li>
<li>Parent2
<ul>
<li>Child1</li>
<li>Child2</li>
<li>Child3</li>
</ul>
</li>
<li>Parent3</li>
<li>Parent4</li>
<li>Parent5</li>
</ul>
</div>
CSS:
#menu {
position:absolute;
top:133px;
left:0px;
width:900px;
height:50px;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
/*padding: 5px 15px 5px 15px;*/
background-image: url(../images/menu1.png);
white-space: nowrap;
width:178px;
height:50px;
}
ul li a:hover {
background: #BBBBBB;
}
li:hover ul {
display: block;
position: absolute;
left:0px;
}
li:hover li {
float: left;
font-size: 11px;
}
li:hover a {
background: #3b3b3b;
}
li:hover li a:hover {
background: #CCC;
}
Thank you very much for your help in advance!
Hope following changes will work for you. Here is the fiddle link. Followings are your css chagnes
#menu {
/*position:absolute;
top:0;
left:0px;*/
width:900px;
height:22px;
background-color:#000;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
line-height:22px;
margin: 0;
padding: 0;
list-style: none;
text-align:center;
}
ul li {
display: block;
float: left;
position:relative;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
/*padding: 5px 15px 5px 15px;*/
background-image: url(../images/menu1.png);
white-space: nowrap;
width:178px;
line-height:22px;
}
ul li:hover a {
background: #BBBBBB;
}
ul li ul {
display: none;
widht:200px;
position:absolute;
left:0;
top:22px;
}
ul li ul li {
float: none;
font-size: 11px;
}
ul li ul li a {
background: #3b3b3b;
background-image:none!important;
}
ul li ul li a:hover {
background: #CCC;
}
ul li:hover ul {
display: block;
position: absolute;
left:0px;
}
To add a background color to your child sub menu:
ul li ul li {
// rules
}
You can also add class to your list items to make it more manageable. For example, you can add a class to the ul of your child menu:
<li>Parent2
<ul class="sub-menu">
<li>Child1</li>
<li>Child2</li>
<li>Child3</li>
</ul>
</li>
Then you can simplify the css to:
.sub-menu li {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
It is good to retain the same width so that you can avoid that weird movement.
Try this
ul li ul li a:hover {
display:block;
background:#000;
float:left;
width:178px;
height:25px;
}
DEMO
I don't know how you want the result to look exactly but you could also use the + selector in your css like this:
ul > li > a:hover+ {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
The + selector as you see after a:hover means that the next element directly after the a:hover-tag will be selected and is this case it will be a ul
You can also specify the element with +ul if you want the ul to be a list and not a flat one like this:
ul > li > a:hover+ul {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
Like this you know that you will only affect the element next to the hovered one
Solution
ul > li:hover > li > a {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
It can be as per requirement
ul > li:hover li a { }
I have a dropdown bar -
<div class="buttonContainer">
<ul>
<li>
<a class="menu1one" href="">Dashboard</a>
</li>
</ul>
<ul>
<li>
<div class="noLink">Tasks</div>
<ul>
<li>View</li>
<li>Edit</li>
<!--[if lte IE 6]></a><![endif]-->
</ul>
<!--[if lte IE 6]></a><![endif]-->
</li>
<li>
<div class="noLink">Dictionaries</div>
<ul>
<li>Needs</li>
<li>Activities</li>
</ul>
<!--[if lte IE 6]></a><![endif]-->
</li>
<li>
<div class="noLink">Admin</div>
<ul>
<li>User Accounts</li>
</ul>
<!--[if lte IE 6]></a><![endif]-->
</li>
</ul>
</div>
CSS -
/*dropdown menu*/
.menu { float:left; width:100%; font-family: arial; border-top:1px solid #4c597f; background-color: #1079b5; min-width:950px; }
.menu .buttonContainer { padding:0 0 0 200px; }
.menu ul { padding:0; margin:0; list-style-type:none; }
.menu ul li { margin:0; float:left; position:relative; background-color:#153d71; }
.menu ul li a, .menu ul li a:visited { float:left; display:block; text-decoration:none; color:#ddf; padding:0px 16px; line-height:25px; height:30px; }
.menu ul li a:hover { background-color:#9fc1ed; color: #153d71;}
.noLink { display:block; color:#ddf; padding:0px 16px; line-height:25px; height:30px; }
.menu ul li:hover { width:auto; }
.menu ul li ul { display: none; }
/* specific to non IE browsers */
.menu ul li:hover ul { display:block; position:absolute; top:30px; left:0; width:154px; border-bottom:1px solid #000; }
.menu ul li:hover ul.endstop { left:-92px; }
.menu ul li:hover ul li ul { display: none; }
.menu ul li:hover ul li a { display:block; background:#1079b5; color:#000; height:auto; line-height:15px; padding:4px 16px; width:120px; border:1px solid #000; border-bottom:0; }
.menu ul li:hover ul li a.drop { background:#ccd no-repeat 3px 8px; }
.menu ul li:hover ul li a:hover { background-color: #153d71; color: #FFFFFF; }
.menu ul li:hover ul li a:hover.drop { background: #ccd no-repeat 3px 8px; }
.menu ul li:hover ul li:hover ul { display:block; position:absolute; left:153px; top:-1px; }
.menu ul li:hover ul li:hover ul.left { left:-153px; }
/* IE6 */
.menu ul li a:hover ul { display:block; position:absolute; top:30px; t\op:33px; background:#153d71; left:0; border-bottom:1px solid #000; }
.menu ul li a:hover ul.endstop { left: -92px; }
.menu ul li a:hover ul li a { display:block; background:#153d71; color:#000; height:1px; line-height:15px; padding:4px 16px; width:154px; w\idth:120px; border:1px solid #000; border-bottom:0; }
.menu ul li a:hover ul li a.drop { background:#ccd url('') no-repeat 3px 8px; padding-bottom:4px; }
.menu ul li a:hover ul li a ul { visibility:hidden; position:absolute; height:0; width:0; }
.menu ul li a:hover ul li a:hover { color:#000; background: #ccd url('') no-repeat 3px 8px; }
.menu ul li a:hover ul li a:hover.drop { background: #ccd url('') no-repeat 3px 8px; }
.menu ul li a:hover ul li a:hover ul { visibility:visible; position:absolute; top:0; color:#000; left:153px; }
.menu ul li a:hover ul li a:hover ul.left { left:-153px; }
The dropdown menu is working well or showing up on hover in IE7 but not responding in Firefox.
Could anybody help me with this please?? I tried position : relative for inner li a:hover and it shows the menu but extends the whole div till its end. What is to be changed here?
Also, i don't want to use javascript/jquery for this.
-thanks
EDITED - I have found the solution to get it to work. I added 'position: absolute;' attribute to the .menu{} in the css. That made it work... Thanks.
I just tested on IE7 its working fine to me
http://jsfiddle.net/vcN5g/
I have found the solution to get it to work. I added 'position: absolute;' attribute to the .menu{} in the css. That made it work... Thanks.