• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

navigation mouseover remains active on pages

How do I modify page so the mouseover effect remains activated when visitor opens a web page?  I created a class but it didn't work right.  I put it on the Caregiving button on this page only.


http://www.embracecaremanagement.com/caregiving.html
http://www.embracecaremanagement.com/embrace.css

<li class="active"><a href="caremanagement.html">Care Management</a></li>
<ul id="nav"> 
   <li><a href="services.html">Services</a></li>
     <li class="active"><a href="caremanagement.html">Care Management</a></li>
     <li><a href="caregiving.html">Caregiving</a></li>
     <li><a href="team.html">Team Members</a></li>
    <li><a href="faq.html">FAQ</a></li>
    <li><a href="testimonials.html">Testimonials</a></li>
    <li><a href="stories.html">Client Stories</a></li>
    <li><a href="news.html">News</a></li>
    <li><a href="video.html">Video</a></li>
    <li><a href="http://sheboyganseniorcare-helpishere.blogspot.com/" target="_blank">Blog</a></li>
    <li><a href="links.html">Links/Resources</a></li>
    <li><a href="contact.html">Contact Us</a></li>
    <li><a href="index.html">Home</a></li>
    </ul>



.active {color: #3b2f18; 
background: #c7e7b7;/* light green mouseover color on button */
background-image:url(img/mouseover2.png);
background-repeat:no-repeat;
background-position:left center;}

Open in new window

0
nsitedesigns
Asked:
nsitedesigns
  • 8
  • 3
  • 2
  • +2
3 Solutions
 
HainKurtSr. System AnalystCommented:
use

<li class="active">Care Management</li>

and modify active a bit to match to a tag...
0
 
jebpotlyCommented:
First issue is knowing which link should be activated. Since this is an html page and not some sort of scripting language page then you will have to use javascript. In your url for the link you can put the name of the link to highlight. Then when the page loads, have javascript set the current link to be active.

This site has a cool function for getting at url parameters: http://www.netlobo.com/url_query_string_javascript.html

Here is the resulting page which works for me:
<ul id="nav"> 
   <li id="services"><a href="services.html?page=services">Services</a></li>
     <li id="caremanagement"><a href="caremanagement.html?page=caremanagement">Care Management</a></li>
     <li id="caregiving" ><a href="caregiving.html?page=caregiving">Caregiving</a></li>
     <li id="team"><a href="team.html?page=team">Team Members</a></li>
    <li id="faq"><a href="faq.html?page=faq">FAQ</a></li>
    <li id="testimonials"><a href="testimonials.html?page=testimonials">Testimonials</a></li>
    <li id="stories"><a href="stories.html?page=stories">Client Stories</a></li>
    <li id="news"><a href="news.html?page=news">News</a></li>
    <li id="video"><a href="video.html?page=video">Video</a></li>
    <li><a href="http://sheboyganseniorcare-helpishere.blogspot.com/" target="_blank">Blog</a></li>
    <li id="links"><a href="links.html?page=links">Links/Resources</a></li>
    <li id="contact"><a href="contact.html?page=contact">Contact Us</a></li>
    <li id="index"><a href="index.html?page=index">Home</a></li>
    </ul>

<style type="text/css">

.active {color: #3b2f18; 
background: #c7e7b7;/* light green mouseover color on button */
background-image:url(img/mouseover2.png);
background-repeat:no-repeat;
background-position:left center;}
</style>
<script type="text/javascript">
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function setActive(el_id) {
	var elem = document.getElementById(el_id);
	var is_active = (gup('page') == el_id);
	if (is_active) {
		elem.className  = 'active';
	} else {
		elem.className  = 'inactive';
	}
}
window.onload = function () {
	setActive('caremanagement');
	setActive('caregiving');
	setActive('team');
	setActive('faq');
	setActive('stories');
	setActive('testimonials');
	setActive('news');
	setActive('video');
	setActive('links');
	setActive('contact');
	setActive('index');
	setActive('services');
}
</script>

Open in new window

0
 
nsitedesignsAuthor Commented:
HainKurt,

How do I modify the css?  That is my question.

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
GreatGermCommented:
What's happening is that the style in .active are being overridden by the styles in ul#nav li a since it cascades down.  Either you can move the location of the declaration or you can use the !important rule for anything that you want to break the cascade.  You just place it in line with the style:

background: #c7e7b7 !important;
0
 
nsitedesignsAuthor Commented:
greatGerm,

I tried moving the css down the sheet and adding the important tag to the background and this is what happened.

http://screencast.com/t/VxLizwgrwUI
0
 
nsitedesignsAuthor Commented:
Oops - I see what I did to get the goofy results with the link above.  I fixed that.  But still not getting the results that I am hoping for.

Back to square one.
0
 
GreatGermCommented:
Not square one :)

Change .active to .active a
0
 
nsitedesignsAuthor Commented:
You are right, square two.  : )

adding "a" to active worked partially.  I had to add important! to all active declarations.  Is that ok to do?  I heard to use important! sparingly.

.active a {color: #3b2f18!important;
background: #c7e7b7 !important;/* light green mouseover color on button */
background-image:url(img/mouseover2.png)!important;
background-repeat:no-repeat!important;
background-position:left center!important;}
0
 
David S.Commented:
If you used "ul#nav .active a" (which has a higher specificity) instead of ".active a", then you wouldn't need to add "!important".
0
 
GreatGermCommented:
Yes, you would need to add the !important rule to all declarations that are overridden down the cascade.

You are correct, you will want to use it sparingly since it does break out of the cascade, but this is the type of situation for which it was meant.  Like most things CSS you have other options such as changing the order of the declarations, putting the styles inline, using client-side scripting (i.e. javascript), etc.

How you do it is up to you.
0
 
nsitedesignsAuthor Commented:
Hey Kravimir!

I removed the important! from the declaration and changed it to "ul#nav .active a" but that only worked partially.  I see the green bar now but not the little ball to the left.  The link below is the only page that I have this applied to:  See what I mean...  What did I miss?

http://www.embracecaremanagement.com/caregiving.html

ul#nav .active a {color: #3b2f18; 
background: #c7e7b7;/
background-image:url(img/mouseover2.png);
background-repeat:no-repeat;
background-position:left center;}

Open in new window

0
 
nsitedesignsAuthor Commented:
I moved the declaration lower on the css page too and it still doesn't seem to work...
0
 
David S.Commented:
It's not working because of the stray slash at the end of this line:

background: #c7e7b7;/
0
 
nsitedesignsAuthor Commented:
Wahoo-dilly-do!

thanks.  Time for new glasses I guess.
0
 
nsitedesignsAuthor Commented:
Thanks all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now