SirGabriel
11-04-2010, 10:55 PM
Hello,
I am trying to center the navigation menu bar with css. I finally got it near the center rather than left-aligned, but I can't get it to perfectly center for some reason. Here are the CSS and HTML codes:
CSS:
body { width: 100%; margin: auto; background-color: #CCC884; text-align: center; }
#container {
width: 100%; height: 240px; margin: 0px auto; background-image: url(../multimedia/CTLHeader.jpg); background-repeat: no-repeat;
}
#navbar { height: 45px;
width: 100%;
margin: 0px;
background-color: #130940;
border: #130940 5px 0px;
border-style: inset none;
text-align: center;
position: relative; top: 140px; }
#menu { width: 100%; height: 45px; margin: 0px; list-style: none; }
ul#menu li { display: inline-block; }
ul#menu li a {
line-height: 45px;
padding: 0px 20px;
letter-spacing: 2px;
font-size: 18px;
color: #99C;
text-decoration: none; }
ul#menu li a:hover {background-color: #; line-height: 45px; padding: 20px 20px 18px 20px;}
ul#menu li a.current {background-color: #130920; padding: 13px 20px 13px 20px; }
#main { margin: 0px auto; position: relative; top: 240px; text-align: center; }
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cameron Telecom Law | CTL</title>
<link type="text/css" rel="stylesheet" href="css/ctl.css" />
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onload="MM_preloadImages('multimedia/HeaderRollover.jpg','multimedia/HeaderRolloverText.jpg')">
<div id="container">
<div id="header">
<div id="navbar">
<ul id="menu">
<li><a class="current" href="homemade.html">Home</a></li>
<li><a href="homemade.html">Services</a></li>
<li><a href="homemade.html">About</a></li>
<li><a href="homemade.html">Contact</a></li>
<li><a href="homemade.html">Links</a></li>
</ul>
</div>
</div>
<div id="main">
<h1>This is the main content area. Isn't it just lovely?</h1>
</div>
<div id="footer">
</div>
<!-- end of container div --></div>
</body>
</html>
I've read a few books about CSS and HTML and taken a few classes but that was a few months ago, so I'm a bit rusty. Hope you can help!
I am trying to center the navigation menu bar with css. I finally got it near the center rather than left-aligned, but I can't get it to perfectly center for some reason. Here are the CSS and HTML codes:
CSS:
body { width: 100%; margin: auto; background-color: #CCC884; text-align: center; }
#container {
width: 100%; height: 240px; margin: 0px auto; background-image: url(../multimedia/CTLHeader.jpg); background-repeat: no-repeat;
}
#navbar { height: 45px;
width: 100%;
margin: 0px;
background-color: #130940;
border: #130940 5px 0px;
border-style: inset none;
text-align: center;
position: relative; top: 140px; }
#menu { width: 100%; height: 45px; margin: 0px; list-style: none; }
ul#menu li { display: inline-block; }
ul#menu li a {
line-height: 45px;
padding: 0px 20px;
letter-spacing: 2px;
font-size: 18px;
color: #99C;
text-decoration: none; }
ul#menu li a:hover {background-color: #; line-height: 45px; padding: 20px 20px 18px 20px;}
ul#menu li a.current {background-color: #130920; padding: 13px 20px 13px 20px; }
#main { margin: 0px auto; position: relative; top: 240px; text-align: center; }
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cameron Telecom Law | CTL</title>
<link type="text/css" rel="stylesheet" href="css/ctl.css" />
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onload="MM_preloadImages('multimedia/HeaderRollover.jpg','multimedia/HeaderRolloverText.jpg')">
<div id="container">
<div id="header">
<div id="navbar">
<ul id="menu">
<li><a class="current" href="homemade.html">Home</a></li>
<li><a href="homemade.html">Services</a></li>
<li><a href="homemade.html">About</a></li>
<li><a href="homemade.html">Contact</a></li>
<li><a href="homemade.html">Links</a></li>
</ul>
</div>
</div>
<div id="main">
<h1>This is the main content area. Isn't it just lovely?</h1>
</div>
<div id="footer">
</div>
<!-- end of container div --></div>
</body>
</html>
I've read a few books about CSS and HTML and taken a few classes but that was a few months ago, so I'm a bit rusty. Hope you can help!