CSS hover and active selection for UL - css

Hi I have different colors for hover and active menu items. The problem is that when an item is active it changes color when hovered. I want it to maintain its active color. I mean I don't want the hover color to apply to an active menu item.
CSS:
li a:hover{
color: black;
text-shadow: 0px 1px 0px black;
}
li.active a{
color: #f37121;
font-weight: bold;
font-size: 17px;
}

You can add inheritance to active link.
Just adding:
li.active a:hover{ color: inherit;}

You could apply a :not() (CCS3 selectors are pretty well supported nowerdays) to specify you only want the changes to happen on anchor tags that do not have the .active class
li:not(.active) a:hover {
color: black;
text-shadow: 0px 1px 0px black;
}
http://jsfiddle.net/srqnuyp7/3/
Or you could simply add text-shadow:none; as an additional rule
li.active a {
text-shadow:none;
}
http://jsfiddle.net/srqnuyp7/2/

You can simply use :not(selector). This matches every element that isn't selector.
You just need to add this into your first rule for li.
li:not(.active) a:hover{ color: black; text-shadow: 0px 1px 0px black;}
Run the snippet below:
li:not(.active) a:hover{ color: black; text-shadow: 0px 1px 0px black;}
li.active a { color: #f37121; font-weight: bold; font-size: 17px;}
<li>inactive link 1</li>
<li class="active">active link</li>
<li>inactive link 2</li>

Related

how to customize :active link color for only for one menu item in WordPress?

I've added book-table class for the last menu item and tried to customize it. The main trouble is that hover works default mode works but when it's active and you are locating on that specific page active color doesn't work. It extends default active link color which is for other menu items. Here is the code:
.book-table {
background-color:#e67e22;
color: #ffffff;
border: 2px solid;
border-color: #e67e22;
line-height: 3.5;
border-radius:40px;
padding-left:10px;
padding-right:10px;
}
.book-table:hover {
background-color: #ff8214;
border: 2px solid;
border-color: #ff8214;
line-height: 0;
border-radius:40px;
padding-left:10px;
padding-right:10px;
}
.book-table a:hover,
.book-table a:focus,
.book-table a:active {
color: #222222 !important
}
.book-table > li > li.current-menu-item > a {
color: #fff
}
Is there any way to change active color only for this latest menu link?

Why is my CSS for removing border-right on a class being ignored?

In my code I got border-right on all of my li elements. I'm trying to get rid of the border-right when a li element is active using an own made class named active. The problem is that my class does not remove the border-right.
This is a JSFiddle of the code as well: http://jsfiddle.net/t0a4j5tq/2/
div#navbar {
width: 250px;
height: 550px;
float: left;
}
div#navbar > ul {
text-align: center;
background-color: #EEE;
}
div#navbar > ul > li.li, div#navbar > ul > li.liLast {
list-style-type: none;
border-bottom: 1px solid black;
border-right: 1px solid black;
font-size: 25px;
font-family: Algerian, "Times New Roman";
}
div#navbar > ul > li > a {
color: black;
text-decoration: none;
display: block;
width: 100%;
padding: 38px 0;
-webkit-transition: margin-left 0.5s;
}
div#navbar > ul > li > a:hover {
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black, 0 0 5px black;
margin-left: 5px;
}
li.active {
box-shadow: inset 3px 3px 10px #333;
border-right: none;
}
<div id="navbar">
<ul>
<li class="li active">Start</li>
<li class="li">Om mig</li>
<li class="li">Vision</li>
<li class="li">Tjänster</li>
<li class="liLast">Kontakt</li>
</ul>
</div>
The root of your problem is CSS Specificity. This is important to understand, because simply using !important in your code is a hack and can cause you to have problems later on if you forget that you put it there.
!important overrides everything, and so obviously should not be used except in dire, last-resort situations (and even then, many people [myself included] would argue that you should figure out how to fix the problem anyway instead of using !important).
Earlier in your code, you have a CSS selector for the same element (and similar elements):
div#navbar > ul > li.li {
Now, you are trying to access the same element with just this:
li.active {
But the first selector is way more specific. Instead, you should use the following CSS selector, without the !important hack:
div#navbar > ul > li.active {
Hi solution is simple you just need to inform that this change is "important" :P
li.active {
box-shadow: inset 3px 3px 10px #333;
border-right-style: none !important;}
Hope this helps :)

selctor:hover.class applied before hover

I want to apply a link selector hover effect which includes bottom border underline in an unordered list. Really, I know I can do a simple underline using a border-bottom: #FFFFFF solid 2px;, but I'd like to make a custom underline with box-shadow effect. So I have two issues.
my border is showing up all the time, not just when I hover.
When I tried to add a box shadow to my .underline class it goes around the whole list item and does not create a separate line. I guess we can get to this item later.
MY CSS CODE
li {
margin: auto 0px 20px auto;
font: 1em 'Bookman Old Style', Georgia, Garamond, ‘Times New Roman’, Times, serif;
color: #FFFFFF;
}
li a {
text-decoration: none;
color: rgba(255,255,255,0.5);
display: block;
}
li a:hover .underline {
cursor: pointer;
text-decoration: none;
color: rgba(255,255,255,1);
}
.underline {
border-bottom: #FFFFFF solid 2px;
}
MY HTML CODE
<ul>
<li><a class="underline" href="http://www.sitepoint.com/">SitePoint.com</a></li>
<li>Revealing CSS3 Menu</li>
</ul>
I would really like to be pointed to a comprehensive article about how to build rich HTML elements via CSS specfically using :before and :after and being able to use multiple classes on one selector in CSS properly.
Here is a JSFiddle of what I have (broken) http://jsfiddle.net/jellis3d/a8svpwr4/2/. Also here is a picture of what I'm after. I really exaggerated the underline in order to show what I'm looking for. The line does not have to have rounded edges either.
You could do it by apply border-bottom to .underline:hover and box-shadow and display: inline-block; to li a tag.
JSFiddle - DEMO
HTML:
<ul>
<li><a class="underline" href="http://www.sitepoint.com/">SitePoint.com</a>
</li>
<li>Revealing CSS3 Menu
</li>
</ul>
CSS:
body {
background: gray; /* only for demo */
}
li {
margin: auto 0px 20px auto;
font: 1em'Bookman Old Style', Georgia, Garamond, ‘Times New Roman’, Times, serif;
color: #FFFFFF;
}
li a {
text-decoration: none;
color: rgba(255, 255, 255, 0.5);
display: inline-block;
box-shadow: 0px 5px 5px #000;
}
li a:hover .underline {
cursor: pointer;
text-decoration: none;
color: rgba(255, 255, 255, 1);
}
.underline:hover {
border-bottom: #FFFFFF solid 2px;
}
i have made a basic demo on js fiddle showing what i think your after
jsfiddle link
it uses the below css which im sure you can then see what i did and make it into what your after.
li a{
color:blue;
text-decoration:none;
}
li a:hover{
color:red;
border-bottom: black solid 1px;
box-shadow: 10px 10px 5px #888888;
}
You want to add a box-shadow effect on hovering, right? You don't need to use an extra element like .underline then. Just add it to li a:hover
li a:hover {
cursor: pointer;
text-decoration: none;
color: rgba(255,255,255,1);
box-shadow: 0 1px 0 0 rgba(0,0,0,1);
}
You can read more about pseudo-elements like :before and :after on W3C: http://www.w3schools.com/css/css_pseudo_elements.asp
I made a small demo with your code using :before on hover: http://jsfiddle.net/m9czpzs5/

Changing text color of active menu item with CSS

I need your help with changing the text color of the active menu item on my website, using CSS.
(It's a Joomla website and I'm modifying the standard Gantry framework template to our needs).
Here is the CSS for the active menu item...
.gf-menu.l1 > li.active {
background: none;
color: #19D57E;
border: none;
border-bottom: 3px solid #19D57E;
border-radius: 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
margin: 0 auto;
padding-top: 1px;
}
And here is the CSS for the passive menu items...
.gf-menu .item {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 21px;
color: #555555;
padding: 4px 8px;
text-align: left;
text-shadow: 0px 0px 0 transparent;
text-decoration: none;
display: block;
outline: 0;
cursor: pointer;
font-weight: bold;
}
What I want is for the color of the text in active menu item to be green (#19D57E).
The active menu item is already displaying a green line at the bottom, but the text color of the menu item remains black like in the passive menu items. As you can see, I have specified the text of the color, but for some reason it is not doing it.
What am I doing wrong?
If you want to have a look at the website, please go to http://www.barrylong.tv/index.php/home
Thanks a lot!
Hector
This is the CSS needed:
.gf-menu.l1 > li.active a {
color: #19D57E;
}
Note the a after .active
Hope this helps
add this in your style sheet .gf-menu > .active > a {
color: #19D57E;
}.
I think you have to change the color of the .item element in the .active li-element. At the moment you are trying to change the color of the li-element and not of the link.
.gf-menu.l1 > li.active .item {
/* ... */
color: #19D57E;
/* ... */
}
Find the CSS block: for item101 active last
Notice in your source for "home":
<li class="item101 active last">
<a class="item" href="/index.php/home">Home </a> </li>
You will see the text color property to change. The reason what you are doing isn't working is that you are changing the wrong CSS block properties.

How to apply CSS to anchor with active class only (parent only) and not include children?

Resolved Thanks!
I need to apply css to the current active menu (PARENT LIST li item), this is my code:
#supermenu li.current-menu-item a, #supermenu li.current-menu-item a:hover {
font-weight: bold;
color: #fff;
background-color: #ea6ea0;
border-right: 1px solid #ea6ea0;
box-shadow:inset 0 -1px 2px #bf1358;
}
Overriding the links for children looking like a long messy process, any clean way to exclude the children links?
but the css get applied to the children LINKS / anchors because it is used in conjuction with dropdown menu, how can I stop the children links from having the same css?
Thanks
If I understand you correctly, please try this:
#supermenu li.current-menu-item > a,
#supermenu li.current-menu-item > a:hover {
font-weight: bold;
color: #fff;
background-color: #ea6ea0;
border-right: 1px solid #ea6ea0;
box-shadow:inset 0 -1px 2px #bf1358;
}
You can take a look at this article to understand the > child combinator.
Note that it doesn't work for IE6 or lower.
Try using the > operator, that will only match the direct descendants.
This should work:
#supermenu li.current-menu-item > a,
#supermenu li.current-menu-item > a:hover {
font-weight: bold;
color: #fff;
background-color: #ea6ea0;
border-right: 1px solid #ea6ea0;
box-shadow:inset 0 -1px 2px #bf1358;
}
Note that IE7 and older doesn't support it.

Resources