Jump to content

Centering things


play_

Recommended Posts

I'm having trouble centering my menu.

 

The way i have always done my menu, was

- i make them a list

- ul, li float to the left

- a display: block

 

but this works when there's a fixed width.

 

Now i just wanna align them in the center of the page.

 

here's the link of what i have (very minimal, for demonstration purpose)

http://purrr.org/del.html

 

Notice how i have the container aligned in the middle of the page, but not the text.

 

I could take out float: left and do display: inline, but then it won't let me add top/bottom padding to the links.

 

 

Thanks.

Link to comment
Share on other sites

I could take out float: left and do display: inline, but then it won't let me add top/bottom padding to the links.

 

Who told you that?

 

Let's remove "text-align:center" from everything but the ul, and add "font-size:small" (which is @ 12px) to the body for a relative size dimension reference (so we can use ems for margin/padding). Also, don't forget to add type="text/css" to the style tag:

 

Then:

<style type="text/css">
body, html {
	margin: 0;
	padding: 0;
	font-size:small
}

.menu-holder{
	border: 1px solid red;


}

.menu {
	margin: 0 auto;
	background: #eee;
	width: 500px;
}

.menu ul {
	margin: .5em 0;
	padding: 0;
	list-style: none;
	text-align: center;

}

	.menu li {
	margin: .5em;
	padding: .25 .5em;
	display:inline;
}


</style>

 

This will center the list AND separately permit margins/paddings on both the ul and li elements

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.