Hi,
I wondered if I could ask a further question: I have a navigation list marked up as follows:
The css used to style the nav is below:
In order to get the ul to center horizontally within the div #navtop, I've had to set an explicit width on the ul and then use auto left and right margins as follows:
To get it centered correctly I have to get the width of the ul as close to the combined width of the li elements so that it centers perfectly. The problem is that I don't know what the combined width of the li elements is because I haven't set this explicitly, therefore I have to guess at the width, then test, then tweak some more etc. Then I finally get it right so that it looks good in safari on my mac and then I test on internet explorer on a pc and it's not wide enough there.
So I guess I'm asking is there an easier way to center the ul within a div?
Thanks again for any further help offered.
I wondered if I could ask a further question: I have a navigation list marked up as follows:
Code:
<div id="navtop"> <ul>
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Partners</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Feedback</a></li>
<li id="home"><a href="#">Online store</a></li>
</ul>
</div>
The css used to style the nav is below:
Code:
#navtop ul {
list-style: none;
margin: 0 auto 0;
width: 650px;
padding: 12px 0 12px;
}
#navtop li {
display: inline;
float: left;
border-right: 1px dotted #fff;
}
#navtop li#home {
border: none;
}
#navtop a:link, #navtop a:visited {
display: block;
padding: 0.4em 1.8em 0.4em 1.8em;
color: #fff;
text-decoration: none;
}
#navtop a:hover {
color: #634A95;
}
In order to get the ul to center horizontally within the div #navtop, I've had to set an explicit width on the ul and then use auto left and right margins as follows:
Code:
#navtop ul {
list-style: none;
margin: 0 auto 0;
width: 650px;
padding: 12px 0 12px;
}
To get it centered correctly I have to get the width of the ul as close to the combined width of the li elements so that it centers perfectly. The problem is that I don't know what the combined width of the li elements is because I haven't set this explicitly, therefore I have to guess at the width, then test, then tweak some more etc. Then I finally get it right so that it looks good in safari on my mac and then I test on internet explorer on a pc and it's not wide enough there.
So I guess I'm asking is there an easier way to center the ul within a div?
Thanks again for any further help offered.