Jump to content

<solved>centering A Menu


Ruud

Recommended Posts

I got some trouble here. I wat to center a menu but I can't manage to do so. Code for the menu is:

/* The menu */#slant {padding:0; margin:30px 0 100px 20px; list-style:none;}#slant li {float:left; text-align:center; margin-right:-20px;} #slant a {display:block; text-decoration:none;}#slant a em {font-style:normal; display:block; padding:0 15px; height:25px; background:#363; float:left; cursor:pointer; color:#beb; line-height:24px;}#slant a b, a span {cursor:pointer; display:block; width:0; overflow:hidden; float:left; background:#363;}#slant a span {height:0; border-top:25px solid #363; border-right:25px solid #fff;}#slant a b.p1,#slant a b.p2,#slant a b.p3,#slant a b.p4,#slant a b.p5 {border-top:5px solid #fff; border-right:5px solid #363;}#slant a b.p1 {height:0; margin-top:20px;}#slant a b.p2 {height:5px; margin-top:15px;}#slant a b.p3 {height:10px; margin-top:10px;}#slant a b.p4 {height:15px; margin-top:5px;}#slant a b.p5 {height:20px;}#slant a b.p6,#slant a b.p7,#slant a b.p8,#slant a b.p9,#slant a b.p10 {border-bottom:5px solid #fff; border-left:5px solid #363;}#slant a b.p6 {height:20px;}#slant a b.p7 {height:15px;}#slant a b.p8 {height:10px;}#slant a b.p9 {height:5px;}#slant a b.p10 {height:0;}#slant a:hover {background:#696;}#slant a:hover em, #slant a.selected em {color:#030; background:#696;}#slant a:hover b.p1, #slant a.selected b.p1,#slant a:hover b.p2, #slant a.selected b.p2,#slant a:hover b.p3, #slant a.selected b.p3,#slant a:hover b.p4, #slant a.selected b.p4,#slant a:hover b.p5, #slant a.selected b.p5 {border-right-color:#696; background: #696;}#slant a:hover b.p6, #slant a.selected b.p6,#slant a:hover b.p7, #slant a.selected b.p7,#slant a:hover b.p8, #slant a.selected b.p8,#slant a:hover b.p9, #slant a.selected b.p9,#slant a:hover b.p10, #slant a.selected b.p10 {border-left-color:#696; background: #696;}#slant a:hover span, #slant a.selected span {border-top-color:#696;}#slant a.selected:hover b, #slant a.selected:hover em, #slant a.selected:hover span {cursor:default;}

Any help would be more then welcome.

Link to comment
Share on other sites

 <ul id="slant"><li><a href="slanty.html?current=one"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Item One</em><span></span></a></li><li><a href="slanty.html?current=three"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Longer Item Three</em><span></span></a></li><li><a href="slanty.html?current=four"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Four</em><span></span></a></li><li><a href="slanty.html?current=five"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>.. and Five</em><span></span></a></li><li><a href="slanty.html?current=six"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>6</em><b class="p6"></b><b class="p7"></b><b class="p8"></b><b class="p9"></b><b class="p10"></b></a></li></ul>

Link to comment
Share on other sites

Well, the fact is that you're floating the list items to the left inside a container that takes the full width of the screen. That makes it difficult to center.What you can do is count the amount of <li> elements there are and calculate the percentage of width each one should have so that they all fit well and equally spaced inside the <ul>. After that, you have to give the <ul> a defined width and add margin: auto to it to center it.It would be something like this:

#slant { padding:0; margin:30px auto 100px auto; list-style:none; width: 80%; }#slant li { float: left; text-align: center; width: 20%; }

Link to comment
Share on other sites

I didn't expect it to work, it has to be adapted to your site. Make sure your list items do not have borders and that you have a fixed amount of them.I would have to see the site in order to know better what to do.

Link to comment
Share on other sites

This is the HTML code:

<!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>Untitled Document</title><link href="css/main.css" rel="stylesheet" type="text/css" /><!--[if IE]><style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */.thrColLiqHdr #sidebar2, .thrColLiqHdr #sidebar1 { padding-top: 30px; }.thrColLiqHdr #mainContent { zoom: 1; padding-top: 15px; }/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */</style><![endif]--><style type="text/css"><!--.thrColLiqHdr #container #footer h6 {	text-align: center;}.thrColLiqHdr #container #sidebar2 h5 {	text-align: center;}.curlycontainer{border: 1px solid #b8b8b8;margin-bottom: 1em;}.curlycontainer .innerdiv{background: transparent url(images/brcorner.gif) bottom right no-repeat;position: relative;left: 2px;top: 2px;padding: 1px 4px 15px 5px;}.thrColLiqHdr #container #header h5 {	text-align: right;}--></style></head><body class="thrColLiqHdr"><div id="container"> <div id="header">  <h5>Male | Female | Signout</h5>  <ul id="slant"><li><a href="slanty.html?current=one"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Mainpage</em><span></span></a></li><li><a href="slanty.html?current=three"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Survival</em><span></span></a></li><li><a href="slanty.html?current=four"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Combat</em><span></span></a></li><li><a href="slanty.html?current=five"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Articles</em><span></span></a></li><li><a href="slanty.html?current=five"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Library</em><span></span></a></li><li><a href="slanty.html?current=five"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Updates</em><span></span></a></li><li><a href="slanty.html?current=five"><b class="p1"></b><b class="p2"></b><b class="p3"></b><b class="p4"></b><b class="p5"></b><em>Contact</em><span></span></a></li></ul>  <!-- end #header --></div>  <div id="sidebar1">  <? include("form.php"); ?>  <!-- end #sidebar1 --></div>  <div id="sidebar2">   <h5>Advertisement</h5>	<h3><a href="http://www.******.nu"><img src="images/SMR.jpg" alt="smr" width="140" height="140" border="0" align="absmiddle" /></a></h3>  <!-- end #sidebar2 --></div>  <div id="mainContent"><div class="curlycontainer"><div class="innerdiv">	<h1> Main Content </h1>	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at,  odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. </p>	</div></div><div class="curlycontainer"><div class="innerdiv">	<h2>H2 level heading </h2>	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>	</div></div>	<!-- end #mainContent --></div>	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />  <div id="footer">	<h6>www.*******.com & www.******.com</h6>  <!-- end #footer --></div><!-- end #container --></div></body></html>

This is the CSS code:

@charset "utf-8";body  {	font: 100% Verdana, Arial, Helvetica, sans-serif;	background: #666666;	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */	padding: 0;	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */	color: #000000;}.thrColLiqHdr #container { 	width: 80%;  /* this will create a container 80% of the browser width */	background: #FFFFFF;	margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */	border: 1px solid #000000;	text-align: left; /* this overrides the text-align: center on the body element. */} .thrColLiqHdr #header {	background: #FFFFFF;	padding: 0 10px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */	text-align: right;} .thrColLiqHdr #header h1 {	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */	padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */	text-align: right;}/* Tips for sidebars:1. Since we are working in percentages, it's best not to use side padding on the sidebars. It will be added to the width for standards compliant browsers creating an unknown actual width. 2. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColLiqHdr #sidebar1 p" rule.3. Since Explorer calculates widths after the parent element is rendered, you may occasionally run into unexplained bugs with percentage-based columns. If you need more predictable results, you may choose to change to pixel sized columns.*/.thrColLiqHdr #sidebar1 {	float: left; /* this element must precede in the source order any element you would like it be positioned next to */	width: 16%; /* since this element is floated, a width must be given */	background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */	padding: 15px 0; /* top and bottom padding create visual space within this div  */	border-right: 1px solid #000000;	text-align: center;}.thrColLiqHdr #sidebar2 {	float: right; /* this element must precede in the source order any element you would like it be positioned next to */	width: 16%; /* since this element is floated, a width must be given */	background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */	padding: 15px 0; /* top and bottom padding create visual space within this div */	border-left: 1px solid #000000;}.thrColLiqHdr #sidebar1 p, .thrColLiqHdr #sidebar1 h3, .thrColLiqHdr #sidebar2 p, .thrColLiqHdr #sidebar2 h3 {	margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */	margin-right: 10px;	font-family: "Courier New", Courier, monospace;	text-align: center;}/* Tips for mainContent:1. the space between the mainContent and sidebars is created with the left and right margins on the mainContent div.2. to avoid float drop at a supported minimum 800 x 600 resolution, elements within the mainContent div should be 300px or smaller (this includes images).3. in the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs.*/.thrColLiqHdr #mainContent { 	margin: 0 20% 0 20%; /* the right and left margins on this div element creates the two outer columns on the sides of the page. No matter how much content the sidebar divs contain, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the sidebar spaces when the content in each sidebar ends. */}.thrColLiqHdr #footer { 	padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */	background:#FFFFFF;} .thrColLiqHdr #footer p {	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */}/* Miscellaneous classes for reuse */.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */	float: right;	margin-left: 8px;}.fltlft { /* this class can be used to float an element left in your page The floated element must precede the element it should be next to on the page. */	float: left;	margin-right: 8px;}.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain its child floats */	clear:both;	height:0;	font-size: 1px;	line-height: 0px;}/* The menu */#slant {padding:0; margin:30px 0 100px 20px; list-style:none;}#slant li {float:left; text-align:center; margin-right:-20px;} #slant a {display:block; text-decoration:none;}#slant a em {font-style:normal; display:block; padding:0 15px; height:25px; background:#363; float:left; cursor:pointer; color:#beb; line-height:24px;}#slant a b, a span {cursor:pointer; display:block; width:0; overflow:hidden; float:left; background:#363;}#slant a span {height:0; border-top:25px solid #363; border-right:25px solid #fff;}#slant a b.p1,#slant a b.p2,#slant a b.p3,#slant a b.p4,#slant a b.p5 {border-top:5px solid #fff; border-right:5px solid #363;}#slant a b.p1 {height:0; margin-top:20px;}#slant a b.p2 {height:5px; margin-top:15px;}#slant a b.p3 {height:10px; margin-top:10px;}#slant a b.p4 {height:15px; margin-top:5px;}#slant a b.p5 {height:20px;}#slant a b.p6,#slant a b.p7,#slant a b.p8,#slant a b.p9,#slant a b.p10 {border-bottom:5px solid #fff; border-left:5px solid #363;}#slant a b.p6 {height:20px;}#slant a b.p7 {height:15px;}#slant a b.p8 {height:10px;}#slant a b.p9 {height:5px;}#slant a b.p10 {height:0;}#slant a:hover {background:#696;}#slant a:hover em, #slant a.selected em {color:#030; background:#696;}#slant a:hover b.p1, #slant a.selected b.p1,#slant a:hover b.p2, #slant a.selected b.p2,#slant a:hover b.p3, #slant a.selected b.p3,#slant a:hover b.p4, #slant a.selected b.p4,#slant a:hover b.p5, #slant a.selected b.p5 {border-right-color:#696; background: #696;}#slant a:hover b.p6, #slant a.selected b.p6,#slant a:hover b.p7, #slant a.selected b.p7,#slant a:hover b.p8, #slant a.selected b.p8,#slant a:hover b.p9, #slant a.selected b.p9,#slant a:hover b.p10, #slant a.selected b.p10 {border-left-color:#696; background: #696;}#slant a:hover span, #slant a.selected span {border-top-color:#696;}#slant a.selected:hover b, #slant a.selected:hover em, #slant a.selected:hover span {cursor:default;}

Link to comment
Share on other sites

Hi, i just happen to had a time to check your code, this would center your menu:#slant {padding:0; margin:30px 0 100px 50px; list-style:none;}but still doesn't make me too happy that a text-align: center; don't do it, it might be receiving the align rule from somewhere else.

Link to comment
Share on other sites

Hi, i just happen to had a time to check your code, this would center your menu:#slant {padding:0; margin:30px 0 100px 50px; list-style:none;}but still doesn't make me too happy that a text-align: center; don't do it, it might be receiving the align rule from somewhere else.
Great that one did the trick, thanks people for the effort.
Link to comment
Share on other sites

Usefull input...
oh yeah? you're going to be bothered by someone laughing at someone's else joke? that's not even about you? :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...