Forum Moderators: not2easy
<div id="wrapper">
<div id="Navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Something</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
html, body {margin: 0; padding: 0;}
#wrapper {
width: 960px;
margin: 0 auto;
}
#Navbar {
width: 80%;
padding: 0 10%; /* width + padding = 100% = 960px width of container */
background: #060;
text-align: center;
}
#Navbar ul {
background: #090;
width: 100%;
word-spacing: -4px; /* to make inline-blocks have no space between them */
}
#Navbar ul, #Navbar li {
list-style: none;
margin: 0;
padding: 0;
}
#Navbar li {
vertical-align: top;
color: #F5F5F5;
background-color: #0C0;
width: 20%; /* 4 links x 20% = 80% which leaves 10% either side for effect */
min-width: 100px;
font-size: 110%;
display: inline-block;
word-spacing: 0; /* reset for text inside list items */
}
#Navbar li { /* for IE 6 & 7 - asterisk before the rule is the hack */
*display: inline;
}
#Navbar li a {
padding: 10px 0;
display: block;
color: #f5f5f5;
background-color: #0C0;
text-decoration: none;
}
#Navbar li a:hover {
color: #000;
background: orange;
}
<style type="text/css">
html, body {
margin: 0;
padding: 0;
}
#wrapper {
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
float: left;
position: relative;
left: 50%;
}
#Navbar {
width: 80%;
min-width: 790px;
min-height: 41px;
text-align: center;
background-image: url(http://img151.imageshack.us/img151/2232/examplerd.png); /* Temporary external image, for ease of your editing*/
background-repeat: no-repeat;
background-position: right top;
left: -50%;
position: relative;
}
#NavMiddle {
min-height: 41px;
background-image: url(http://img27.imageshack.us/img27/2603/examplelwh.png); /* Temporary external image, for ease of your editing*/
background-position: left top;
background-repeat: no-repeat;
margin-right: 241px;
}
#NavInner {
margin-right: -241px; /* Found it was necessary to get Right image to show */
}
#Navbar ul {
width: 100%;
word-spacing: -4px;
margin-left: 241px;
}
#Navbar ul, #Navbar li {
list-style: none;
margin: 0;
padding: 0;
}
#Navbar li {
vertical-align: top;
color: #F5F5F5;
width: 14%;
font-size: 110%;
display: inline-block;
word-spacing: 0;
}
#Navbar li { /* for IE 6 & 7 - asterisk before the rule is the hack */
*display: inline;
}
#Navbar li a {
display: block;
color: #f5f5f5;
text-decoration: none;
padding-top: 10px;
padding-right: 0;
padding-bottom: 10px;
padding-left: 0;
}
#Navbar li a:hover {
color: #000;
background-color: #CCC;
}
</style>
<div id="wrapper">
<div id="Navbar">
<div id="NavMiddle">
<div id="NavInner">
<ul>
<li><a href="#">Home</a></li><!--
--><li><a href="#">Something</a></li><!--
--><li><a href="#">About</a></li><!--
--><li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
# The Right image really does need to be transparent, so I did as you suggested (make another wrapper, of sorts). It works, but in IE7 the Left (extremely long) image doesn't show up (I expect I bodged the coding up somehow).
# Unfortunately, my original problem of the li's not expanding and shrinking based on there percentages, is still there.
*Note. Expands in Opera and Google Chrome, but not FireFox, Safari, or IE.
# In IE7 there is no space between the li's,.
display: inline-block; to inline elements.. i.e. elements that would normally have that default word-spacing in the first place.. the hack in your code actually makes IE display the li elements as inline, and in normal circumstances you wouldn't be able to apply a width or height to them.. which is what you want by choosing inline-block.. however IE will give an inline element height and width honoring capabilities if it's hasLayout trigger is set to true.. zoom: 1; in your previous hack was doing that.. in my version display: inline-block is actually doing that5 but only if it's not in the same rule as the other display property # I have centered the Navbar using 2 div's: 1 Floating left with position: relative, and Left 50%, the other with position: relative, Left -50%. However for some reason this does not work in Opera.
margin: 0 auto; centering code to it too, you can change the width of the wrapper to see the effect of the overall centering .. like if your overall container has a width of it's own in all you should not need floats or relative positioning to center any of this :) <div id="wrapper">
<div id="Navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Something</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
html, body {
margin: 0;
padding: 0;
}
#wrapper {
margin: 0 auto;
width: 960px;
width: 100%;
}
#Navbar {
width: 80%;
margin: 0 auto; /* center this too if it's less width than the container */
min-width: 790px;
min-height: 41px;
text-align: center;
background-image: url(http://img151.imageshack.us/img151/2232/examplerd.png);
background-repeat: no-repeat;
background-position: right top;
}
#Navbar ul, #Navbar li { /* general reset though some margins are redeclared later */
list-style: none;
margin: 0;
padding: 0;
}
#Navbar ul {
min-height: 41px;
background-image: url(http://img27.imageshack.us/img27/2603/examplelwh.png);
background-position: left top;
background-repeat: no-repeat;
margin-right: 241px; /* this is good and the way to be able to use a transparent corner image */
/* width: 100%; */ /* but no explicit width here! or the margin above this is doing nothin.. the ul is already 100% by default */
word-spacing: -4px;
text-align: center; /* add this.. it won't center the blocks any more because of the margin above but add an equivalent of padding the other side to simmulate */
padding-left: 241px; /* add this to even up the size of the ul's content area */
}
#Navbar li {
vertical-align: top;
color: #F5F5F5;
width: 20%; /* increase this a bit there wasn't enough room for the text and it's still leaving a bit of extra space */
font-size: 110%;
display: inline-block;
word-spacing: 0;
}
#Navbar li { /* for IE 6 & 7 - asterisk before the rule is the hack */
*display: inline;
}
#Navbar li a {
display: block;
color: #f5f5f5;
text-decoration: none;
padding-top: 10px;
padding-right: 0;
padding-bottom: 10px;
padding-left: 0;
}
#Navbar li a:hover {
color: #000;
background-color: #CCC;
}
.. Hows that now?
# Unfortunately, my original problem of the li's not expanding and shrinking based on there percentages, is still there.
*Note. Expands in Opera and Google Chrome, but not FireFox, Safari, or IE.
Ok not understanding that one, but perhaps it was related to the fixes I made for the basic centering.
I've enlarged the percentages, and also added a min-width to the li, works well now.
I increased the size of the inline-blocks because at 14% there wasn't enough room for the text in one of them so they only looked like they were not evenly spaced due to the text overflowing.. this is still happening at my 20% if you reduce the browser size.. it's not that the percentages aren't working it's that they're not enough to contain the text.. this will be trial and error to get the optimal solution for when your menu is actually complete.. if it were me I would try to make the total add up to 100% especially if there is to more than 4 items.. in this menu for example if you increase them to 25% they look a little to spaced out at normal resolution, but they will stay looking equally space longer as you narrow your browser window.