Solved

css horizontal menu - equally spacing menu items and right edge alignment

Posted on 2009-07-15
8
782 Views
Last Modified: 2012-05-07
I am using a list for a menu, and I need  all <li> items equally spaced withing given container. Plus the last item of menu (contact) should be aligned against the right edge of container.  So the last letter of the last word is actually touching the right edge.
I tried to do float and use padding, but it is obviously not what i need.

Thank you,

Stacy
0
Comment
Question by:ctasik
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:flob9
ID: 24863459
Please, provide a sample of the html page.
0
 

Author Comment

by:ctasik
ID: 24863524
<div id="header">
    <h1>portfolio</h1>
             
    <ul>
   
    <li><a href="index.htm" class="current">HOME</a></li>
    <li><a href="curr_act.htm">CURRENT ACTIVITIES</a></li>
    <li><a href="gallery.htm">GALLERY</a></li>
    <li><a href="theatre.htm">THEATRE</a></li>
    <li><a href="teaching.htm">TEACHING</a></li>
    <li><a href="contact.htm" class="last">CONTACT</a></li>
         
    </ul>
  </div> <!--header-->


css
------------------------------------------
#header ul {
      margin: 0;
      padding: 0;
      list-style: none;
      position: absolute;
      bottom: 0px;
      width:700px;
      font-size: 1.1em;
      right: 0px;
            }
      
#header li {
      float: left;
      }
      
#header li a:link, #header li a:visited {
      display:block;
      background: #FFFFFF;
      padding: .2em 0em;
      text-decoration: none;
      color:#000000;
      /*margin-right: .5em*/
      margin-left:20px;
      font-family: Arial, Helvetica, sans-serif;
      }            

      
#header li a:hover, #header li a:active {
      color:#666666;
      background:#FFFFFF;
            }
      
#header li a.current, #header li a.current:hover, #header li a.current:active {
      color:#666666;
      background: #FFFFFF;
      cursor: default;
   }
   
0
 
LVL 14

Accepted Solution

by:
flob9 earned 125 total points
ID: 24863638

#header ul {

      margin: 0;

      padding: 0;

      list-style: none;

      position: absolute;

      bottom: 0px;

     /* width:700px;*/

      float:right; /* added */

      font-size: 1.1em;

      right: 0px;

}

Open in new window

0
 

Author Comment

by:ctasik
ID: 24863679
* width:700px;*/
      float:right; /* added */
I tried to float it right, but then Firefox puts all menu items <li> backwards... and Safari doesn't.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:flob9
ID: 24863787
It is working for me with safari 4 and firefox 3.5.

"Firefox puts all menu items <li> backwards" <<< what do you mean ?
0
 
LVL 3

Expert Comment

by:russianryebread
ID: 24863848
If the elements are backwards, float them the other way...  You can re-arrange the order of a floated list by the direction you float the <li> elements inside the <ul>
0
 

Author Comment

by:ctasik
ID: 24865457
Actually it didn't work:)
The distance between menu item is control by margin-left: 20 px
ul float right & il float left  still leaves a distance to the right, because the space occupied by font of <li> items + space in between them still doesn't equal 100%.

I need somehow to tell them to occupy all the space inside ul edge to edge, 100 %. I tryed using percentage value, but each word is different length. So equal percentage method doesn't work.
0
 

Author Comment

by:ctasik
ID: 24865481
so my question now is

How to make <li> items

<li><a href="index.htm" class="current">HOME</a></li>
    <li><a href="curr_act.htm">CURRENT ACTIVITIES</a></li>
    <li><a href="gallery.htm">GALLERY</a></li>
    <li><a href="theatre.htm">THEATRE</a></li>
    <li><a href="teaching.htm">TEACHING</a></li>
    <li><a href="contact.htm" class="last">CONTACT</a></li>

spread inside lu edge to edge with equal spaces between them.

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now