Results 1 to 9 of 9

Thread: Css And JQuery Help For Nav Menu

  1. #1
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Css And JQuery Help For Nav Menu

    Hey Guys,

    I am using this script I found on the net, but I am having issues.

    I am trying to move the css code from html file to the css file but it just stops working after that. Then with the JQuery i changed it from a click to a hover over the arrow but I would like it have it work when the menu section is hovered as well ie: Tutorials.

    Any suggestions or help? I have been at this for days and I am just stuck now.


    JQuery:
    Code:
    // JavaScript Document
    $(document).ready(function(){
    
    	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
    
    	$("ul.topnav li span").hover(function() { //When trigger is clicked...
    
    		//Following events are applied to the subnav itself (moving subnav up and down)
    		$(this).parent().find("ul.subnav").slideDown('slow').show(); //Drop down the subnav on click
    
    		$(this).parent().hover(function() {
    		}, function(){
    			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
    		});
    
    		//Following events are applied to the trigger (Hover events for the trigger)
    		}).hover(function() {
    			$(this).addClass("subhover"); //On hover over, add class "subhover"
    		}, function(){	//On Hover Out
    			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
    	});
    });


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
    <script type="text/javascript" src="js/default.js"></script> 
    <style type="text/css">
    ul.topnav {
    	list-style: none;
    	padding: 0 20px;	
    	margin: 0;
    	float: left;
    	width: 920px;
    	background: #222;
    	font-size: 1.2em;
    	background: url(images/nav/nav_menu_background.gif) repeat-x;
    }
    ul.topnav li {
    	float: left;
    	margin: 0;	
    	padding: 0 15px 0 0;
    	position: relative; /*--Declare X and Y axis base--*/
    }
    ul.topnav li a{
    	padding: 10px 5px;
    	color: #fff;
    	display: block;
    	text-decoration: none;
    	float: left;
    }
    ul.topnav li a:hover{
    	background: url(images/nav/nav_menu_hover.gif) no-repeat center top;
    }
    ul.topnav li span { /*--Drop down trigger styles--*/
    	width: 17px;
    	height: 35px;
    	float: left;
    	background: url(images/subnav_btn.gif) no-repeat center top;
    }
    ul.topnav li span.subhover {background-position: center bottom; cursor: pointer;} /*--Hover effect for trigger--*/
    ul.topnav li ul.subnav {
    	list-style: none;
    	position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
    	left: 0; top: 35px;
    	background: #333;
    	margin: 0; padding: 0;
    	display: none;
    	float: left;
    	width: 170px;
    	-moz-border-radius-bottomleft: 5px;
    	-moz-border-radius-bottomright: 5px;
    	-webkit-border-bottom-left-radius: 5px;
    	-webkit-border-bottom-right-radius: 5px;
    	border: 1px solid #111;
    }
    ul.topnav li ul.subnav li{
    	margin: 0; padding: 0;
    	border-top: 1px solid #252525; /*--Create bevel effect--*/
    	border-bottom: 1px solid #444; /*--Create bevel effect--*/
    	clear: both;
    	width: 170px;
    }
    ul.topnav li ul.subnav li a {
    	float: left;
    	width: 145px;
    	background: #333 url(images/dropdown_linkbg.gif) no-repeat 10px center;
    	padding-left: 20px;
    }
    ul.topnav li ul.subnav li a:hover { /*--Hover effect for subnav links--*/
    	background: #222 url(images/dropdown_linkbg.gif) no-repeat 10px center; 
    }
    </style>
    
    </head>
    
    <body>
    <div class="container">
    
        <div id="header">
            <ul class="topnav">
                <li><a href="#">Home</a></li>
                <li>
                    <a href="#">Tutorials</a>
                    <ul class="subnav">
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#">Resources</a>
                    <ul class="subnav">
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                        <li><a href="#">Sub Nav Link</a></li>
                    </ul>
                </li>
                <li><a href="#">About Us</a></li>
                <li><a href="#">Advertise</a></li>
                <li><a href="#">Submit</a></li>
                <li><a href="#">Contact Us</a></li>
            </ul>
        </div>
    </div>
    </body>
    
    </html>

  2. #2
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default

    have you include the css into the html head? when you remove the style into css file.

    Code:
    <link rel="stylesheet" type="text/css" href="yourStyle.css" />

  3. #3
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    That's not the problem, because I have other css code in the css file that is being read but as soon as I move this css code in there, my nav menu does not work anymore, the layout is gone basically.

    If anyone can test out what I mean, you will see it.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That page works fine, and I see no external styles. Most likely, when you went to make the styles external, one or both of two things happened:

    1. You made a (or placed the menu styles after an existing) syntax error (like including the style tag, etc.), thus invalidating the external version of the styles for the menu.
    2. You changed the effective order of the styles visa vis your other styles and a conflict arose that prevented some or all of the menu styles from being used.


    It could of course be some other issue, like incorrect link tag to the styles, incorrect location in the link tag, etc., too many things to enumerate really. I can't really tell unless I see an example page where the problem actually exists. Please post a link to the actual page with the actual problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Bloodshot (09-27-2009)

  8. #7
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I have the script working but I would like to clean up the css, I am having issue setting a font style just for the nav menu. All the css tags are used as ul.thenav or something like I am not very found of that style i have tried setting it to #thenav ul, li or .thenav ul, li but the whole thing just breaks.

    Here is the html page: http://www.thenerdstop.com/default2.html
    Here is the css page: http://www.thenerdstop.com/css/default2.css
    Here is the js script: http://www.thenerdstop.com/js/default.css

    Thanks

  9. #8
    Join Date
    Sep 2008
    Location
    Seattle, WA
    Posts
    135
    Thanks
    1
    Thanked 11 Times in 11 Posts

    Default

    You just want to change the font family? You'd modify this section:

    ul.topnav li a{
    padding: 10px 5px;
    color: #fff;
    display: block;
    text-decoration: none;
    float: left;
    }


    By adding:

    ul.topnav li a{
    padding: 10px 5px;
    font-family: name of font;
    color: #fff;
    display: block;
    text-decoration: none;
    float: left;
    }

    You could also add:
    font-size: 12pt;
    font-weight: bold;

  10. The Following User Says Thank You to simcomedia For This Useful Post:

    Bloodshot (09-27-2009)

  11. #9
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks guys, I finally got it working...thanks for the help

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
  •