Cannot get :hover to function - html

I am trying to get a mega menu to work by using hover to activate divs
i have tried it numerous ways, but i just cant get them to show on hover
here is the basic idea in jsfiddle : http://jsfiddle.net/mXx64/5/
and here is the code
HTML
<div class="nav-container">
<ul id="mega-menu">
<li class="menu1">
menu1
</li>
<li class="menu2">
menu2
</li>
<li class="menu3">
menu3
</li>
<li class="menu4">
menu4
</li>
</ul>
</div>
<div class="menu-area1">
menu1
</div>
CSS
.nav-container ul li a:hover .menu-area1 {
display: block;
}
.menu-area1 {
display: none;
height: 100px;
width: 100px;
background-color: red;
}
any help would be appreciated
edit please ignore the spelling mistake, i know its there, but the code doesnt work when it is fixed anyway :(

It will not work because your ".menu-area1" is not in the anchor if you want keep this structure you need to add jQuery otherwise just do like below
working- http://jsfiddle.net/R37rr/
<div class="nav-container">
<ul id="mega-menu">
<li class="menu1"> menu1
<div class="menu-area1"> menu1 </div>
</li>
<li class="menu2"> menu2 </li>
<li class="menu3"> menu3 </li>
<li class="menu4"> menu4 </li>
</ul>
</div>
.menu-area1 {
display: none;
height: 100px;
width: 100px;
background-color: red;
}
.nav-container ul>li:hover .menu-area1 {
display: block;
}

I'm not good on JQuery but this what I got:
Fiddle
$('li').hover(function () {
$('.menu-area1').show();
});
$('li').hover('out',function () {
$('.menu-area1').hide();
});

Related

wp_nav_menu add div around li

Using wp_nav_menu, currently it's in three columns, what I need is two li's wrapped in a DIV and third wrapped in another DIV. If it can be done via CSS then that would be great, rather than custom wrapper class for the menu.
Not sure how to do this, so would appreciate some assistance. Thanks.
Edit: Added stylesheet, which is using flex.
==== ==== ====
to
==== ====
====
ul {
display: flex;
flex-wrap: wrap;
}
ul li {
flex-grow: 1;
width: 33%;
}
<ul>
<li>
One
<ul>
<li>1a</li>
<li>1b</li>
<li>1c</li>
</ul>
</li>
<li>
Two
<ul>
<li>2a</li>
<li>2b</li>
</ul>
</li>
<li>
Three
<ul>
<li>3a</li>
<li>3b</li>
<li>3c</li>
</ul>
</li>
</ul>
to
<ul>
<div class="col-2">
<li>
One
<ul>
<li>1a</li>
<li>1b</li>
<li>1c</li>
</ul>
</li>
<li>
Two
<ul>
<li>2a</li>
<li>2b</li>
</ul>
</li>
</div>
<div class="col-4">
<li>
Three
<ul>
<li>3a</li>
<li>3b</li>
<li>3c</li>
</ul>
</li>
</div>
</ul>
If you aren't looking to change the HTML and just use CSS, then using CSS grid rather than flexbox might be what you are looking for.
ul {
display: grid;
grid-template-columns: 1fr 1fr;
max-width: 200px;
padding: 0;
list-style: none;
}
ul > li:last-of-type {
grid-column: 1 / 3;
}
ul ul,
ul ul li {
display: flex;
}
<html>
<ul>
<li>
One
<ul>
<li>1a</li>
<li>1b</li>
<li>1c</li>
</ul>
</li>
<li>
Two
<ul>
<li>2a</li>
<li>2b</li>
</ul>
</li>
<li>
Three
<ul>
<li>3a</li>
<li>3b</li>
<li>3c</li>
</ul>
</li>
</ul>
</html>

CSS for first element with class

I want to change the background of "zxczxczxc" and "bbbbbb" to yellow. I try ul > li:first-child > a {
background: yellow;
} but it is not work. Any one have solution? thanks
Note: No add more class. It's must be css only.
<ul class="sub-menu">
<li>
<a>zxczxczxc</a>
<ul class="sub-menu">
<li><a>ccccc</a></li>
<li><a>bbbbddddddbb</a></li>
</ul>
</li>
<li>
<a>bbbbbb</a>
</li>
</ul>
Your Answer:
.link1{background-color:red}
.link2{background-color:Blue;
color:white;}
<li>
<a class="link1">zxczxczxc</a>
<ul class="sub-menu">
<li><a>ccccc</a></li>
<li><a>bbbbddddddbb</a></li>
</ul>
</li>
<li>
<a class="link2">bbbbbb</a>
</li>
</ul>
Buddy, you have a small typo in your code to set a background color we use background-color
body {
background-color: coral;
}

Horizontal Menu only with Image Css

Am New to Asp.net and CSS.
I Need to Show Horizontal Menu only image like this
image 1 image 2 image 3 image 4
So I tried like this
CSS
#UlIcon
{
height: 100%;
list-style:list-style-image;
text-align:center;
padding-left: 5px;
}
#UlIcon li { display:inline; width : 100px; height:100%;}
#LiNew
{
list-style-image:url(/IMG/New.png);
}
#LiSave
{
list-style-image:url(/IMG/Save.png);
}
#LiDelete
{
list-style-image:url(/IMG/Delete.png);
}
#LiLog
{
list-style-image:url(/IMG/New.png);
}
#Padding-right {padding-right:15px;}
ASP.NET CODE
<div id="DivMenuRight">
<ul id="UlIcon">
<li id="LiNew"></li>
<li id="LiSave"></li>
<li id="LiDelete"></li>
<li id="LiLog"></li>
</ul>
</div>
But it shows empty. If I Remove display: inline in li css, the image shows vertically in center of the div. What am doing wrong here?
How do I get the solution?
Am using Visual Studio 2008 and CSS2.1
the css list-style-image will place an image next to each point or listed text. it act as an image bullet
I am of the opinion you would like to have this
<div id="DivMenuRight">
<ul id="UlIcon">
<li id="LiNew">
<img src="link1">
</li>
<li id="LiSave">
<img src="link2">
</li>
<li id="LiDelete">
<img src="link3">
</li>
<li id="LiLog">
<img src="link4">
</li>
</ul>
</div>
then you can use css to display all list elements inline-block
example display:inline-block
here is a snippet
img {
display:inline-block;
width:50px;
height:50px;
}
li {
display:inline-block;
}
<div id="DivMenuRight">
<ul id="UlIcon">
<li id="LiNew">
<img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTCjDQxLj9LSCLsCI2iCDEawZVlJ7tlRuBQDHenXo_KaFhdTUiTGw">
</li>
<li id="LiSave">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQqyRrA_-5TM0vpRU8BcTPFpGubyzgHGtvE9FQzpnVMPnKnoZwkmQ">
</li>
<li id="LiDelete">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcShZ_bYswgHlQLrUn8egsNTTZn5nCmSz1NcFmvtUzujpZhrBflUiQ">
</li>
<li id="LiLog">
<img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTCjDQxLj9LSCLsCI2iCDEawZVlJ7tlRuBQDHenXo_KaFhdTUiTGw">
</li>
</ul>
</div>

CSS Parent menu stay on highlighted when mouse hover to sub menu

I wanted to let my "Kuantan" menu to stay highlighted after i hover to their child menu which is "kiosk no.35". But i try to change few way to let it stay active but i had failed to do so. Anything i miss out on my code? Please point my wrong. Thanks
Here is the html code:
<ul class="treeview-menu">
<li class="dropdown"><i class="fa fa-angle-double-right"></i> Kuantan
<ul class="nav dropdown-menu" style="width:100px;height:30px">
<li><a href="chooseOption.php?kiosk=35" style="margin-left:-20px;margin-top:-13px;" >Kiosk No.35</a></li>
</ul>
</li>
<li class="dropdown"><i class="fa fa-angle-double-right"></i> UTC Kuantan
<ul class="nav dropdown-menu" style="width:100px;height:30px">
<li><a href="chooseOption.php?kiosk=36" style="margin-left:-20px;margin-top:-13px;" >Kiosk No.36</a></li>
</ul>
</li>
<li class="dropdown"><i class="fa fa-angle-double-right"></i> Temerloh
<ul class="nav dropdown-menu" style="width:100px;height:30px">
<li><a href="chooseOption.php?kiosk=37" style="margin-left:-20px;margin-top:-13px;" >Kiosk No.37</a></li>
</ul>
</li>
<li class="dropdown"><i class="fa fa-angle-double-right"></i> Bentong
<ul class="nav dropdown-menu" style="width:100px;height:30px">
<li><a href="chooseOption.php?kiosk=6" style="margin-left:-20px;margin-top:-13px;" >Kiosk No.6</a></li>
</ul>
</li>
<hr/>
</ul>
Here is the css where i hover the dropdown then the dropdown-menu will came out:
/*3rd level sidebar menu */
.dropdown:hover .dropdown-menu {
display: block;
left:220px;
top:0;
}
What i want is that after i hover the dropdown and went to dropdown-menu, the dropdwn will stay highlighted. Is there possible? Sorry i'm still new to this css skill.
As explained in my comment - .dropdown should still be "highlighted" on :hover, because .dropdown-menu is nested inside it and therefore you are still hovering over .dropdown.
/* Assuming you are making nested lists display:none */
ul{
list-style: none;
}
.dropdown-menu{
display: none;
}
.dropdown:hover{
background: yellow;
}
.dropdown:hover .dropdown-menu {
display: block;
left:220px;
top:0;
}
DEMO HERE
By using jQuery this is one option with your current code (fiddle here: https://jsfiddle.net/j0wLj6z9/)
<script type="text/javascript">
$(document).ready(function(){
$('.dropdown').hover(function(){
$(this).toggleClass('highlighted');
});
});
</script>
and your css is whatever you'd like:
.highlighted
{
background: yellow;
}
Also include jQuery in your project:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

Hover over X or Y to change color of Y only

I'm making a navbar that consists of icons followed by the title of their page (e.g. Icon of a home followed by the text 'Home'). Let's say I want to change the color of only(!) the icon from black (default) to blue when hovering over either the text or the icon itself using the :hover selector. How can I do that? (I don't want to use jQuery, just CSS)
The markup is now something like this:
<ul id="navbar">
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-home"></i></li>
<li class="navname">Home</li>
</ul>
</li>
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-info"></i></li>
<li class="navname">Information</li>
</ul>
</li>
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-contact"></i></li>
<li class="navname">Contact</li>
</ul>
</li>
</ul>
Of course everything is {display:inline}
Set the hover to the ul inside the navgroups. CSS below does that, you can add whatever styling you like to it.
http://jsfiddle.net/PQShS/9/
CSS:
.navgroup ul:hover .navicon{
color:#FFF;
}
Your Code
<ul id="navbar">
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-home"></i></li>
<li class="navname">Home</li>
</ul>
</li>
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-info"></i></li>
<li class="navname">Information</li>
</ul>
</li>
<li class="navgroup">
<ul>
<li class="navicon"><i class="icon-contact"></i></li>
<li class="navname">Contact</li>
</ul>
</li>
</ul>
Since it boils down to changing the look of the icon when the cursor hovers anywhere above the ul element, you can do this:
.navgroup ul:hover .navIcon .icon-home
{
/*hover style for the icon*/
}
.navgroup ul .navIcon .icon-home
{
/*non-hover style for the icon*/
}
You should use the following css:
.navgroup:hover .navicon {
background-color: blue;
}
It will modify just the navicon anytime you hover anywhere within the navgroup
See this jsFiddle
you should use anchor tag
css:
.testing:hover {
color: red;
}
html:
<a class="testing" href="">
<span>hello1</span>
<span style="color:black;">hell2</span>
</a>
Give the whole styling to <a> tag and give the inline styling to other element inside <a> tag that you don't want to change.