Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Dynamic Ajax Content: Styling Selected/Active Link

  1. #1
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default Dynamic Ajax Content: Styling Selected/Active Link

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    3) Describe problem: I have the links set in divs and would like the selected link have a different background & font color using CSS, but am not sure how to achieve that.

    Here is my working sample page: http://www.floridaschoolbreakfast.or...eupsample.html. The dynamic ajax links are set in divs to achieve the desired menu appearance the client wants, but I cannot figure out how to make the selected div for dynamic content have a different appearance from the rest. Here is the relevant CSS I'm using so far:

    Code:
    /* HUDDLE UP MENU */
    
    .huborder { width:100%; border-bottom:0px; width:960px; margin:0px auto; }
    .hutabborder { border-right:1px solid #fff; }
    
    .hutab { float:left; }
    .hutab a:selected { color:#00ad4a; padding:8px 0px; background:#fff; }
    .hutab a:link { color:#fff; padding:8px 0px; background:#00ad4a; }
    .hutab a:visited { color: #fff; padding:8px 0px; background:#00ad4a; }
    .hutab a:hover { color:#fff; background:#52c889; }
    
    .hulink { display:block; padding:8px 0px; text-align:center; text-decoration:none; }
    Thank you in advance for any assistance.
    Deborah
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    The simplest way would be to style the :focus state of the menu's links, something like:

    Code:
    a.hulink:focus{
        background: green !important;
    }
    This should cause the selected menu item's background color to be green.
    DD Admin

  3. The Following User Says Thank You to ddadmin For This Useful Post:

    dmwhipp (06-04-2015)

  4. #3
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    Thank you - I was able to change the font and background color using onfocus in the stylesheet, but the new issue I'm having is when you refresh the page in IE (big surprise). On the sample page, I have the following coding which makes the Welcome message appear as default:

    Code:
    <script>
    ajaxpage('hu-welcome.html', 'contentarea')
    </script>
    Now when I hit refresh, the tab most recently clicked (i.e. Contests, Activities, Recipes, etc.) remains the onfocus color (white background/green font), but the welcome message appears: http://www.floridaschoolbreakfast.or...eupsample.html

    Can you think of any way to fix this?
    Thanks,
    Deborah
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  5. #4
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Have you also noticed that when clicking any link on any page (which then opens in a new tab) the menu on the original page reverts to white text on green background?

  6. The Following User Says Thank You to styxlawyer For This Useful Post:

    dmwhipp (06-04-2015)

  7. #5
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    No... thanks for catching that! So somehow the new menu is interfering with the main site menu. Ugh.
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  8. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Quote Originally Posted by dmwhipp View Post
    Now when I hit refresh, the tab most recently clicked (i.e. Contests, Activities, Recipes, etc.) remains the onfocus color (white background/green font), but the welcome message appears: http://www.floridaschoolbreakfast.or...eupsample.html
    Try explicitly setting focus on the first menu item when the page loads using JavaScript. Firstly, give your first menu item an ID attribute, ie:
    Code:
    <a id="hulink1" class="hulink" href="javascript:ajaxpage('/hu-welcome.html', 'contentarea');">Welcome!</a>
    Then, following the menu markup, do something like the following with JavaScript:

    <script>
    Code:
    document.getElementById('hulink1').focus()
    
    </script>
    I haven't tested to see if this overcomes the bug in IE, but worth a shot.
    DD Admin

  9. #7
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    Thanks... I gave it a try, but no luck: http://www.floridaschoolbreakfast.or...upsample2.html. I appreciate the assistance though
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  10. #8
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    Thanks again for pointing this out. I've been testing different tweaks to the stylesheet and think I have the main menu in the gray bar working correctly on all major browsers/devices now.
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  11. #9
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Try wrapping the code in a window.onload event:

    Code:
    window.onload = function(){
    	document.getElementById('hulink1').focus()
    }
    DD Admin

  12. #10
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    Still a no go: http://www.floridaschoolbreakfast.or...upsample2.html Can you take a look at the code and see if I placed it correctly? I added it to the body tag.
    Thanks!
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

Similar Threads

  1. Tab Content Script (v 2.2) styling active tab
    By Foundas in forum Dynamic Drive scripts help
    Replies: 11
    Last Post: 03-25-2013, 12:35 PM
  2. Active selected link not working
    By jelly46 in forum CSS
    Replies: 2
    Last Post: 09-23-2011, 08:27 AM
  3. Resolved Dynamic Ajax Content SELECTED item in active state
    By verocom in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 08-15-2010, 05:56 AM
  4. Dynamic Ajax Content - active "tab"
    By rian701 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 07-12-2007, 12:03 PM
  5. Dynamic Ajax Content active button
    By quer in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 04-24-2007, 12:05 PM

Bookmarks

Posting Permissions

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