Wrox Programmer Forums
|
BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3
This is the forum to discuss the Wrox book Beginning CSS: Cascading Style Sheets for Web Design by Richard York; ISBN: 9780764576423
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2006, 02:33 PM
Authorized User
 
Join Date: Jan 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Centering an UL element within DIV

I have an unordered list "UL" that contains several "Li" elements and I am having difficulties centering the UL withing the DIV it is contained within. It is aligning itself LEFT and I'd like to have it centered across the page.

<h1>UL table-style menu</h1>
<ul id="ul-table">
<li class="top"><a href="">first link</a></li>
<li class="top"><a href="">second link</a></li>
<li class="top"><a href="">third link</a></li>
<li class="top right"><a href="">fourth link</a></li>
<li><a href="">fifth link</a></li>
<li><a href="">sixth link</a></li>
<li><a href="">seventh link</a></li>
<li class="right"><a href="">eighth link</a></li>
</ul>
<div class="clear"></div>


 
Old March 27th, 2006, 09:10 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

On the UL you want centered, assuming you have set a fixed width on that[list] of some kind, apply the margin: auto; declaration, and that will center the block[list] within the <div>.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old April 4th, 2013, 04:13 PM
Registered User
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Centering an UL element within DIV

first of all you have to move your UL and its related li elements to be btween
<div> and </div> Tags, so they will be related to the div element, then you have several options to centering your UL menu, choose one of them.

1- using css code to DIV will center all text including your menu.
Code:
text-align: center;

2- adding some padding space to DIV will move all div element to start after 70 pixel from the left.
Code:
padding-left:70px;

3- moving the main DIV position to the place to want by add this code
Code:
    position: fixed; 
    top: 100px;
    left: 200px;





Similar Threads
Thread Thread Starter Forum Replies Last Post
div element in array won't display onload linus9 BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 5 November 6th, 2008 02:08 AM
remove <div>-element Kabe Classic ASP Professional 0 November 9th, 2007 05:41 AM
create <ul> with alternating class on <li> element Brian Campbell XSLT 2 November 3rd, 2006 06:07 PM
Something about li and ul sfs00784 CSS Cascading Style Sheets 1 July 31st, 2005 02:03 AM
Change height of div element if < window height JoelJunstrom Javascript How-To 1 October 10th, 2003 09:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.