Spruce interactive

Noise

Simple Responsive Menu with LessCSS

Posted: July 22nd, 2012

Author: KJ Parish

 Details

While this next tip is incredibly short and sweet, it’s a great little method I’ve discovered for making a nice, responsive menu using an unordered list and LESSCSS.

See a live demo of this menu here.

Let’s set up a quick example. In this case, we have 5 list items, and we want our overall (responsive) layout to have a maximum width of 1024px and a minimum width of 480px. We want our navigation menu to scale down from 1024px to 480px with a minimal amount of code.

Basic Navigation Menu Code

<body>
   <div id="content">
        <h1>Responsive Menu with LessCss</h1>
        <nav>
            <ul>
                <li>Menu Item 1</li>
                <li>Menu Item 2</li>
                <li>Menu Item 3</li>
                <li>Menu Item 4</li>
                <li>Menu Item 5</li>
            </ul>
        </nav>
    </div>
</body>

Include LESSCSS

Make sure you put lesscss in your header…for more detailed info check out http://lesscss.org/

<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>

Include LESSCSS

Now we can go ahead and include our styles using LESSCSS nesting and one tiny little math operation. Our navigation menu is within a wrapping div with a minimum/maximum width definition, and we are telling each list item to display as a block object, floated left (to appear in a horizontal orientation). We don’t need to calculate the actual percentage of each list item. We just say the width is equal to the full width divided by the total number of list items (in this case 5).

#content {min-width:480px; max-width:1024px; font-size:1em; font-family:Arial, Helvetica, sans-serif; margin:0 auto;
  h1 {font-size:2em; padding:1em 0;}
  nav {width:100%;
    ul li {display:block; width:100% / 5; background-color:#333; padding: 10px 0; color:#FFF; float:left; text-align:center;}
  }
}

See a live demo of this menu here.

Talk to Us

Wise men have said, "All good things must come to an end", and so it was with Spruce. We began our first project in 2006, and completed our last in Fall 2013. It's been a wonderful experience, but now it's time to begin the next adventure.

Though...we wouldn't want to leave you hanging, now would we? Here are our top recommendations for world-class branding, design, and web development:

  • Kristina (KJ) Parish and Beam Collective:
    KJ provided the artistic vision that allowed Spruce to succeed, and we still think she's the greatest designer in the entire world. She's started a new collective with some talented developers, and is covering much the same territory as Spruce--design and development all under one roof, with a caliber of service and professionalism seldom seen in this business or any other. If you like what you see on the Spruce site, then definitely get in touch with KJ at kj@beamcollective.com
  • Permanent Art & Design
    Permanent is a nationally recognized design & branding firm out of Minneapolis, MN. They've been a long term collaborator and strategic partner over the past couple years, and we'd recommend them for medium to large sized businesses/organizations who are serious about putting their best foot forward. In addition to design, Permanent offers strategy and marketing services, plus in-house and networked developers. For more information contact Joseph Belk joseph@permanentadg.com
  • Nate Thompson
    A freelancer, Nate reminds us of ourselves back in the day. Smart, communicative, and skilled, Nate is our recommendation for small to medium sized businesses/organizations who have sites built on Wordpress or other open source content management solutions. With a background in both design and development, he's a one-stop shop for most web-related tasks. You can get in touch at nate.a.thompson@gmail.com
  • Kevin DeBernardi
    Designer turned developer, Kevin is embarking on a freelance web career after working as the in-house designer at the Museum of the City of New York. He's adept at translating his design ideas into custom PHP code, and is constantly expanding his technical palette. Kevin's a good choice for projects that don't quite fit into the Wordpress mold, and that would benefit from a consistency of presence and vision from design through execution. Kevin can be reached at kevin@analoglifestyle.com