Hi I want to select the "Link" in class beers only but It always select all the links from sub-menu. I try
.beers:first-child does not work
.beers a:nth-child(1) does not work
.beers a:first-of-type (this apply to all the links of sub-menu)
<ul>
<li class="beers"><a>Link</a> only here
<ul class="sub-menu">
<li ><a></a></li> not here
<li><a></a></li> not here
</ul>
</li>
<li ><a></a></li>
<li ><a></a></li>
</ul>
Please help me
If you want to use style for a
.beers > a{color:green;}
If you want to use for li you have override
li.beers{ color:green;}
li.beers ul li{ color:black;}
You can get first element from child as below:
<style>
.beers >a {
background-color:red;
}
You have to maintain the elements level. Try the below one.
.beers>a
.beers:first-child
to
.beers li:first-child
With:
<ul class="beers">
<li><a>Link</a> only here
<ul class="sub-menu">
<li ><a></a></li> not here
<li><a></a></li> not here
</ul>
</li>
<li ><a></a></li>
<li ><a></a></li>
Related
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;
}
<div class="menu">
<ul>
<li>
<ul class="sub-menu">
<li>
<ul class="sub-menu">
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Could You please tell me how to target just first ul element with "sub-menu" class as on an example above? Every pseudo-class I know targets both "sub-menu" ul-s at the same time.
One option:
ul:not(.sub-menu) > li > .sub-menu {
...
}
I'm using [class*="menu-class-"]:not(.menu-class-2) for my <li> elements, it works properly. The problem is when I want to point to the <a> tag inside the <li>, [class*="menu-class-"]:not(.menu-class-2) a. For some reason it doesn't work.
CSS:
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) {
display: table-cell;
}
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) a {
text-transform: uppercase;
}
HTML
<ul class="nav-menu" id="menu-main-navigation">
<li class="menu-class">
Nav 1
<ul class="sub-menu">
<li class="menu-class-3">
Nav 2
<ul class="sub-menu">
<li class="menu-class-2">Anchor, it should be lowercase</li>
</ul>
</li>
</ul>
</li>
</ul>
The problem is the <a> inside the <li class="menu-class-2"> is uppercase, but it should be lowercase, because I didn't add any property for this element. The container of the <a> (<li class="menu-class-2">), didn't get the display:table-cell property, so it works properly.
The JSFiddle link: http://jsfiddle.net/qnzos5t4/3/
The reason is because you do have a li that is not .menu-class-2:
<ul class="nav-menu" id="menu-main-navigation">
<li class="menu-class">
Nav 1
<ul class="sub-menu">
<li class="menu-class-3"> <!-- THIS ONE HERE -->
Nav 2
<ul class="sub-menu">
<li class="menu-class-2">Anchor, it should be lowercase</li>
</ul>
</li>
</ul>
</li>
</ul>
Since your css rule is using a whitespace to select the anchor after the li, every <a> descendant of it, will be uppercase. You need to use a child selector:
Updated JsFiddle
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) > a {
Following is my listing:-
<div class="box">
<div class="box-heading">Menu</div>
<div class="box-content">
<ul>
<li>My Account</li>
<li>Edit Account</li>
<li>Password</li>
<li>Contact Admin</li> <!--display none-->
<li>Address Books</li><!--display none-->
<li>Emails & Notifications</li><!--display none-->
<li>Order Now</li>
<li>Order History</li><!--display none-->
<li>Pending Orders</li>
<li>Current Orders</li>
<li>Completed Orders</li>
<li>Downloads</li>//display none
<li>Newsletter</li>//display none
<li>Logout</li>
</ul>
</div>
</div>
I dont want to display the following list they are:-
Contact Admin
Address Books
Emails & Notifications
Order History
Downloads
Newsletter
using css how can i display the above list as none
THanks in advance.
The most flexible solution is to add a class to the list items you want to hide, e.g.:
<li>My Account</li>
<li>Edit Account</li>
<li>Password</li>
<li class="foo">Contact Admin</li> <!--display none-->
<li class="foo">Address Books</li><!--display none-->
<li class="foo">Emails & Notifications</li><!--display none-->
<li>Order Now</li>
<li class="foo">Order History</li><!--display none-->
<li>Pending Orders</li>
Then
.foo {
display: none;
}
Live Example
But if you can't do that, you pretty much have no choice but to use :nth-child (counting starts with 1, unlike most programming stuff):
ul li:nth-child(4),
ul li:nth-child(5),
ul li:nth-child(6),
ul li:nth-child(8) {
display: none;
}
Live Example
That would, of course, hide those list items in every list, so you'll want to lock that down a bit more specifically.
The problem with doing it this way is, of course, that if you modify the list later, you have to change those indexes. It's fragile. Using a class is more robust.
CSS:
.hidden
{
display:none;
}
HTML:
<li class="hidden">Contact Admin</li> <!--display none-->
<li class="hidden">Address Books</li><!--display none-->
<li class="hidden">Emails & Notifications</li><!--display none-->
<li>Order Now</li>
<li class="hidden">Order History</li><!--display none-->
If you want to use in-line css you should add a style to your ul element:
<li style="display:none;">
otherwise you use a class and setting the property display:none;
<style>
.hide{
display:none;
}
</style>
<li class="hide">
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.