Results 1 to 5 of 5

Thread: Highlight specific Menu-Item via CSS possible?

  1. #1
    Join Date
    Apr 2012

    Highlight specific Menu-Item via CSS possible?


    I want to highlight a single menu-item in my sidebar when there's a campaign.
    The menu is generated dynamically and this cannot be solved on this level, so I am wondering, if I can select and highlight via CSS by name of the menu-entry ('Membership').

    Any ideas?

    I cannot change the menu generation-code, else I would assign an ID and highlight this via CSS.

    Can I include a CSS path to find any menu-entry with the name 'Memership' and highlight it? Is this possible?

    I also want to highlight the current selected menu item in the menu dynamically, too.

    HTML Code:
    #navi #menue .current-menu-item > a,
    #navi #menue .current-menu-ancestor > a,
    #navi #menue .current_page_item > a,
    #navi  #menue .current_page_ancestor > a,
    #Rahmen #Navigation .current-menu-item > a,
    #Rahmen #Navigation .current-menu-ancestor > a,
    #Rahmen #Navigation .current_page_item > a,
    #Rahmen #Navigation .current_page_ancestor > a {
      font-weight: bold;
      color: yellow;

    HTML Code:
    <div id="navi">
      <ul id="menue">
       <li class="document"><a class="" href="/index.php?tpl=page&id=18&lng=en">Home</a></li>
       <li class="folder"><a class="" href="/index.php?tpl=page&id=19&lng=en">Medicine ↘</a>    <ul style="display:none;">   <li class="document"><a class="" href="/index.php?tpl=page&id=21&lng=en">Medical Uses</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=35&lng=en">Side effects</a></li>
       <li class="document"><a class="" href="/index.php?tpl=studylist&id=36&lng=en">Studies and Case Reports</a></li>
      </li>   <li class="folder"><a class="" href="/index.php?tpl=page&id=37&lng=en">Science ↘</a>    <ul style="display:none;">   <li class="document"><a class="" href="/index.php?tpl=deflist&id=38&lng=en">Definitions</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=39&lng=en">List of Clinical Studies</a></li>
       <li><a class=""  href="/studies/study.php">Database of Clinical Studies</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=244&lng=en">Review on Clinical Studies 2005-2009</a></li>
      </li>   <li class="folder"><a class="" href="/index.php?tpl=page&id=41&lng=en">Laws and Politics ↘</a>    <ul style="display:none;">   <li class="document"><a class="" href="/index.php?tpl=page&id=236&lng=en">Overview English</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=245&lng=en">Canada</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=42&lng=en">Finland</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=43&lng=en">France</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=44&lng=en">Germany / Deutschland</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=45&lng=en">Israel</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=46&lng=en">New Zealand</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=47&lng=en">Spain / Espa˝a</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=48&lng=en">Sweden</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=235&lng=en">The Netherlands / Nederland</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=234&lng=en">UK</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=49&lng=en">United States of America</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=246&lng=en">▄bersicht deutsch</a></li>
      </li>   <li class="folder"><a class="" href="/index.php?tpl=page&id=50&lng=en">Archive ↘</a>    <ul style="display:none;">   <li><a class=""  href="/english/bulletin/bulletin.php">Bulletin</a></li>
      </li>   <li class="document"><a class="" href="/index.php?tpl=faqlist&id=53&lng=en">FAQ</a></li>
       <li class="document"><a class="" href="/index.php?tpl=ukpage&id=252&lng=en">UK</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=69&lng=en">Links</a></li>
       <li class="folder"><a class="" href="/index.php?tpl=page&id=72&lng=en">About us ↘</a>    <ul style="display:none;">   <li class="document"><a class="" href="/index.php?tpl=page&id=73&lng=en">Introduction</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=74&lng=en">Board of Directors</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=75&lng=en">Statutes</a></li>
      </li>   <li class="document"><a class="a" href="/index.php?tpl=page&id=76&lng=en">Membership</a></li>
       <li class="document"><a class="" href="/index.php?tpl=page&id=77&lng=en">Imprint</a></li>
    <div id="Rahmen">
    		<ul id="Navigation">
       <li><a class="" href="/index.php?tpl=page&id=1&lng=en">Newsletter</a>    <ul>   <li><a class=""  href="/english/bulletin/bulletin.php">Bulletin</a></li>
       <li><a class=""  href="/english/subscribe.htm" target="_blank">Subscribe &#x21a6;</a></li>
       <li><a class="" href="/index.php?tpl=page&id=7&lng=en">About the Journal</a></li>
       <li><a class="" href="/index.php?tpl=page&id=8&lng=en">For Authors</a></li>
       <li><a class="" href="/index.php?tpl=journallist&id=9&lng=en">Journals</a></li>
      </li>   <li><a class="" href="/index.php?tpl=page&id=10&lng=en">Conference</a>    <ul>   <li><a class=""  href="http://www.conference.com/" target="_blank">2011 &#x21a6;</a></li>
       <li><a class="" href="/index.php?tpl=archivlist&id=12&lng=en">Former</a></li>
        		</ul><li><a href="#">Language</a>
        				<li><a href="/index.php?lng=en">English</a></li>
        				<li><a href="/index.php?lng=de">Deutsch</a></li>
        				<li><a href="/index.php?lng=fr">Fran&ccedil;ais</a></li>
        				<li><a href="/index.php?lng=nl">Nederlands</a></li>
        				<li><a href="/index.php?lng=es">Espa&ntilde;ol</a></li>
        				<li><a href="/index.php?lng=po">Portugu&ecirc;s</a></li>
    It does not work.

  2. #2
    Join Date
    Mar 2011
    If you can generate the CSS file dynamically, you might be able to use an attribute selector to highlight the current page with something like:
    a[href$="tpl=page&id=246&lng=en"] { font-weight:bold; color:yellow; !important; }
    and dynamically insert the value for the 'href' based on the current page.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Apr 2012
    found it, the
    is used for common prefix-matching.

    For others:
    $(document).ready( function() {
      $('[href^="/index.php?tpl=page&id=76&"]').css({'color': 'yellow', 'font-weight': 'bold'}); /* All 'Membership'-links. */
      $('[href^="/index.php?tpl=page&id=1&"]').css({'color': 'yellow', 'font-weight': 'bold'}); /* All 'Newsletter'-links. */
      $('a[Rundbrief]').css("color", "yellow"); /* German special case. */
    //  '<a class="" href="#">Rundbrief</a>'
    });  // end document.ready()
    Now I have two questions left:

    How can I select this link by it's displayed linkname?
    <div id="Rahmen">
      <ul id="Navigation">
        <li><a class=""  href="#">Rundbrief</a>
    This does not work:
      $('a[Rundbrief]').css("color", "yellow"); /* German special case. */
    and the issue to display the currently opened menu-item via CSS only (or also via jQuery)

    #navi #menue .current-menu-item > a,
    #navi #menue .current-menu-ancestor > a,
    #navi #menue .current_page_item > a,
    #navi  #menue .current_page_ancestor > a,
    #Rahmen #Navigation .current-menu-item > a,
    #Rahmen #Navigation .current-menu-ancestor > a,
    #Rahmen #Navigation .current_page_item > a,
    #Rahmen #Navigation .current_page_ancestor > a {
      font-weight: bold;
      color: yellow;
    This does not work yet.

  4. #4
    Join Date
    Mar 2011
    Your code:
    $(document).ready( function() {
      $('[href^="/index.php?tpl=page&id=76&"]').css({'color': 'yellow', 'font-weight': 'bold'}); /* All 'Membership'-links. */
      $('[href^="/index.php?tpl=page&id=1&"]').css({'color': 'yellow', 'font-weight': 'bold'}); /* All 'Newsletter'-links. */
      $('a[Rundbrief]').css("color", "yellow"); /* German special case. */
    //  '<a class="" href="#">Rundbrief</a>'
    });  // end document.ready()
    is doing in jQuery is doing the same thing I suggested in pure CSS. That is, you could just use:
    a[href^="/index.php?tpl=page&id=76&"] { font-weight:bold; color:yellow; !important; }
    a[href^="/index.php?tpl=page&id=1&"] { font-weight:bold; color:yellow; !important; }
    and not rely on JavaScript at all.

    Changing the style of a link based on its content would require JavaScript. The only way I know to do it would be something like:
     links = document.getElementsByTagName('a');
      for (i=0; i<links.length; i++) {
       if (links[i].innerHTML == 'Rundbrief') {
         links[i].style.color = 'yellow';
         links[i].style.fontWeight = 'bold';
       } // endif
      } // end for i
    jQuery probably has a more compact method of doing this, but it should give you a start.
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Apr 2012
    is doing in jQuery is doing the same thing I suggested in pure CSS.
    great idea, I thought it was jQuery Sizzle-synthax, but CSS-selectors are even better. Strange thing, I cannot make them work. The CSS-code does nothing on my site.

    The Rundbrief-problem I solved with your Javascript function, as there are several more '#'-links, so all would turn up bold and yellow.
    Later a redesign of the HTML and the CSS is planned.

    Thank you for the support!

    For reference: I also posted here and interlink the threads:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12464 seconds
  • Memory Usage 2,932KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (9)bbcode_code
  • (2)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates