Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Style Unique CSS Navigation Menu

Tags:

css

navigation

I have a fair amount of CSS knowledge, but I've been stumped while trying to achieve a unique navigation bar for a website I'm working on.

Since pictures are worth over 9000 words, I put together a diagram to represent the scenario.

Diagram

The #container (blue) is 1000px wide and has 25px rounded corners. At the top of the container is the #navbar (green) which is the full width of the #container and is 55px high (it matches the top, left, and right edges of the #container, but I enlarged it in the image so you could see it better). Inside of the #navbar are the different navigation buttons (red). I want all of the buttons to be equally wide (and always stretch from one side to the other), and the buttons on the far left/right to have rounded corners like the grandparent #container. The solution need to be pure and strict CSS and work across most modern browsers (except IE 8 and under).

I want this to be a learning experience, so if you post the code, please provide some explanation.

like image 784
Sonic42 Avatar asked Feb 22 '23 23:02

Sonic42


2 Answers

HTML:

<nav>
    <span>1</span>
    <span>2</span>
    <span>3</span>
</nav>

<div id="container">
</div>

You should probably turn that into a list...

CSS:

nav {
    display: table; /* see below */
    width: 1000px;
}
#container {
    height: 400px;
    width: 1000px;
    background: blue;
    border-radius: 0 0 25px 25px; /* top-left top-right bottom-right bottom-left */
}
nav span {
    display: table-cell; /* spreads them equally across, no matter how many elements */
    height: 55px;
    background: green;
}
nav span:first-child {
    border-radius: 25px 0 0 0;
}
nav span:last-child {
    border-radius: 0 25px 0 0;
}

Here's the fiddle: http://jsfiddle.net/GHVSZ/

like image 123
Joseph Silber Avatar answered Mar 07 '23 11:03

Joseph Silber


updated:

check this fiddle: http://jsfiddle.net/jQpF8/4/

is this what you need?

to set equal widths, you should manually set the widths using percentages (total width of nav bar/no. of links) of the links or set it via JS in case of dynamically changing number of links.

like image 35
Joseph Avatar answered Mar 07 '23 12:03

Joseph