
Originally Posted by
Hulbert Lee
Hi Dresdon, it seems like what you have said is somewhat risky...
I went to another forum and someone said that the reason it wasn't working was because I was running into a box model problem. He suggested changing the padding and margins to 0, and then going up from there trying to use ems or percentages instead of pixels. He didn't specify how to do this though? Can you help me with this?
That's nonsense I'm afraid and won't help you. You have been given the correct answers above.
1) This is what Ralph mentioned.
Code:
#navigation{
float:none;
overflow:hidden;
width:100%;
}
.nav{
background-color: #003D52;
overflow:hidden;
width:100%;
}
#navigation .nav li.page-item-575{
float:right;
padding:0;
}
The div holding the ul and list element is changing from floating to non floated so that it stretches to 100% width automatically and the overflow:hidden is added to clear the child floats. The background colour is then put on the ul so that it fills in any gaps left by the list elements. The last list element is then floated right and the padding from the list removed so that it sits flush and allows a little more space for browsers differences.
You cannot make a number of items fit exactly across the screen by using the content (text) + padding. Browsers render text widths at different sizes and with rounding issues also coming into play there could be differences of up to 25px along the length of a line so that approach will never work.
2) A better approach would be not to float the last list item, remove horizontal padding from the list and anchor and then set the last list item to overflow:hidden and it will automatically fill the rest of the space and allows a greater soak up for browser text width differences.
Here is the code to add to do that. (this is mutually exclusive to the other code I gave you so use one or the other and not both).
Code:
#navigation{
float:none;
overflow:hidden;
width:100%;
}
#navigation .nav li.page-item-575{
float:none;
overflow:hidden;
padding-right:0;
padding-left:0;
text-align:center;
}
#navigation .nav li.page-item-575 a{
padding-right:0;
padding-left:0;
}
Just add that code after the existing styles in your css.
3) A third and more convoluted approach would be to set the width exactly for each item in pixels so that they add up to the total width. You wouldn't need horizontal padding as you could just set text-align:center on each element. This has the benefit that text size can be increased quite a bit before before the nav breaks as there is room in each list item to expand without impact on anything else.
Number 2 is my recommended approach but be aware that users with larger font sizes or when the browser's text size is resized will see your text wrap to the next line and break the layout.
Bookmarks