0

I am evolving a top navigation menu which will provide a different layout for fullsize screens and mobile screens. This intended to follow the usual convention of reducing the menu to a single full-width button on a mobile, and clicking that button will dropdown the menu choices.

Broadly, it is working well but I am having a problem getting the formatting right. The full width version is fine (mid-grey for each button and a slightly darker grey on hover). However in the mobile version, it appears that the first menu item ("HOME") displays the .nav format and all the others display the .nav li or .nav li a formatting.

I supect that it is the jQuery that is the problem, but not sure.

$(document).ready(function(){ 
    var touch   = $('#touch-menu');
    var nav     = $('.nav');

    $(touch).on('click', function(e) {
        e.preventDefault();
        nav.slideToggle();
    });

    $(window).resize(function(){
        var w = $(window).width();
        if(w > 767 && nav.is(':hidden')) {
            nav.removeAttr('style');
        }
    });

});

Here is a jsfiddle to show the problem.

How can I make all the menu lines look the same?

3
  • If it's a formatting issue, it's not the Jquery. Compare teh styling of the .mobile-nav a to your normal nav li a and see if there are any differences. Commented Feb 27, 2014 at 12:14
  • You're using jQuery for checking the width of window and CSS @media both together; Why? Commented Feb 27, 2014 at 12:17
  • Updated the fiddle: jsfiddle.net/RZs49/3 Commented Feb 27, 2014 at 12:23

2 Answers 2

2

It's because you specified the height of the ul item .nav

It will work if you remove the height and set overflow: hidden to get the background colour to fill the nav.

.nav{
     display:block;
     list-style-type:none;
     margin:0;
     padding:0;
     overflow: hidden;
     font:12px Geneva, Arial, Helvetica, sans-serif;
     background:#ccc;
     border:1px solid #999
}

http://jsfiddle.net/RZs49/3/

Sign up to request clarification or add additional context in comments.

4 Comments

You might want to note that this happens because of floated list items.
I've accepted the answer of @MattP. It's not quite the end of the story though because overflow:hidden stops the sub-menu from working. There are still some issues with borders, but I'll work on it. Thanks, All.
I'll also look into the comment from @Hashem Qolami to see if that has any bearing on things.
The overflow:hidden was really to make the background colour work, consider moving the background colour to the .nav li
0

Also, if you add text-align: center; to the .mobile-nav class, then the "Menu" in the mobile version will align properly.

3 Comments

"Menu" was only thrown into the jsfiddle to save having to link to a graphic. Having said that, I did start off with the word "Menu" in there as well and my problem (unsolved, as yet) was vertical alignment, not horizontal.
I removed the height (39px) from .mobile-nav and changed your padding setting to 14px 2%, That gave me perfect vertical alignment. Hope that helps!
@B R, that works with text on it's own but unfortunately not when the text has to share space with an image. The text is then forced to the bottom of the mobile-nav space. I do find that alignment in CSS is a dog's breakfast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.