www.webdeveloper.com
Results 1 to 14 of 14

Thread: Responsive web navigation

  1. #1
    Join Date
    Dec 2002
    Location
    US
    Posts
    128

    Responsive web navigation

    Hello,

    I'm am trying to create my first responsive website from this Youtube Video here. The problem I am having is the navigation structure. When I click on the menu it doesn't expand or collapse. I started my layout using CSS portal and then tried to follow the video and even looked at the code. I don't know what I'm doing wrong. That shutter icon looks neat, how is that done? If anyone can help me get the navigation structure fixed I would appreciate it. Here Is my source code below.

    CSS File
    Code:
    @import url("reset.css");
    body {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 13px;
        color: #333;
        margin:0;
        padding:0;
    }
    p {
        padding:10px;
    }
    a {
        text-decoration:none;
        color:inherit;
    }
    #wrapper {
        margin: 0 auto;
        width: 100%;
    }
    #header {
        float:left;
        height:75px;
        width: 100%;
        padding: 40px 0;
        background: #00795F;
        color: #FFFFFF;
        text-align:center;
    }
    #navigation {
        float:left;
        height: 50px;
        width: 100%;
        background: #FFCC33;
    }
    #navigation ul {
        background-color: #43a286;
        overflow: hidden;
        color: #FFFFFF;
        padding: 0;
        text-align: center;
        margin: 0;
        -webkit-transition: max-height 0.4s;
        -ms-transition: max-height 0.4s;
        -moz-transition: max-height 0.4s;
        -o-transition: max-height 0.4s;
        transition: max-height 0.4s;
    }
    #navigation ul li {
        display: inline-block;
        padding: 20px;
    }
    #navigation ul li:hover {
        background-color:#399077;
    }
    #content {
        margin: 0 auto;
        background: #FFFFFF;
        width: 75%;
        line-height:1.5em;
        font-size: 0.9em;
        padding: 20px;
        clear: both;
    }
    #footer {
        height: 40px;
        width: 100%;
        background: #00795F;
        color: #FFFFFF;
        text-align:center;
        clear: both;
    }
    .handle {
        width: 100%;
        background: #005c48;
        text-align:left;
        box-sizing: border-box;
        padding: 15px 10px;
        cursor: pointer;
        color: #FFFFFF;
        display: none;
    }
    @media screen and (max-width: 580px) {
        #navigation ul {
        	max-height: 0;
        }
        .showing {
        	max-height: 20em;
        }
        #navigation ul li {
            box-sizing: border-box;
        	width: 100%;
            padding: 15px;
            text-align: center;
        }
        .handle {
        	display:block;
        }
    
    }
    HTML Page

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>CSS Portal - Layout</title>
    <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../css/712916.css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    </head>
    <body>
        <div id="wrapper">
            <div id="header">
                <h1>Best Responsive Website</h1>
            </div>
            <div id="navigation">
            	<ul class="showing">
    		<li><a href="#">Home</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Blog</a></li>
    		<li><a href="#">Shop</a></li>
                    <li><a href="#">Gallery</a></li>
    		<li><a href="#">Contact</a></li>	
    		</ul>
    		<div class="handle">Menu</div>
            </div>
            <div id="content">
               <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. </p><p>Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. </p><p>Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. </p>
           </div>
            <div id="footer">
                <p>This is the Footer</p>
            </div>
        </div>
        <script>
    	$('.handle').on('click', function(){
    	   $('navigation ul').toggleClass('showing'); 
    	});
    	</script>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2014
    Posts
    17
    hover on an li maybe your problem, from looking at your css.

    that is really an anchor pseudo class, so not got great browser support on a list item...

  3. #3
    Join Date
    Mar 2014
    Posts
    17
    you need to add a # onto your navigation call in the js, as you have it on the div as an id.

    you also need to add

    #navigation ul.showing {max-height:100%;}

    as your intent is to add that class to the ul so it will pick up a standard max-height, as it is set to be 0 making it hidden.

  4. #4
    Join Date
    Mar 2014
    Posts
    17
    oh you had that style already, beg ya pardon.

  5. #5
    Join Date
    Dec 2002
    Location
    US
    Posts
    128
    The Youtube video shows the list wrapped in anchor tags. I tried it but didn't make any difference. It also doesn't validate.

  6. #6
    Join Date
    Mar 2014
    Posts
    17
    Ur error is here

    $('navigation ul').toggleClass('showing');

    Should be

    $('#navigation ul').toggleClass('showing');

  7. #7
    Join Date
    Dec 2002
    Location
    US
    Posts
    128
    I made the change to the following below but the navigation still doesn't work.

    $('#navigation ul').toggleClass('showing');

  8. #8
    Join Date
    Mar 2014
    Posts
    17
    Is the class being added? I got ur code to work. Make sure the class is being added, inspect the HTML and do a mouse hover..

  9. #9
    Join Date
    Dec 2002
    Location
    US
    Posts
    128
    Yes, the class is added to the HTML. When I shrink the browser window the menu nav displays but I cannot click on it. Look at the attachment picture.

  10. #10
    Join Date
    Mar 2014
    Posts
    17
    Quote Originally Posted by ecross View Post
    Yes, the class is added to the HTML. When I shrink the browser window the menu nav displays but I cannot click on it. Look at the attachment picture.
    http://jsfiddle.net/LXwgB/

    see that and check all the code out.. )

    thanks

  11. #11
    Join Date
    Mar 2014
    Posts
    17
    Remove height from navigation in CSS.

  12. #12
    Join Date
    Dec 2002
    Location
    US
    Posts
    128
    That did the trick! I don't know why it did not work locally on my computer but Jsfiddle.net worked. I had to remove the height from the navigation and change the JQuery version from 1.10.0 to 1.11.0.

  13. #13
    Join Date
    Dec 2002
    Location
    US
    Posts
    128
    Just noticed a problem in Firefox.

    This doesn't happen in IE or Google Chrome Browser. Not sure what will fix this but if you resize the browser window you'll notice Firefox has an issue the nav bar width. The navigation goes past the header. Here is a screenshot.
    Attached Images Attached Images

  14. #14
    Join Date
    Mar 2014
    Posts
    17
    Check padding and margins first off. Inspect with dev toolbar to see where its inheriting the extra width from..

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



Recent Articles