473,747 Members | 2,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

centering list elements

I'm trying to center list elements in a webpage I'm working on, and
setting margin-left to auto for ol (or ul) seems to prevent the number
(or bullet) from displaying in IE6 (strict mode) and Opera7 (it works
fine in Firefox). Any ideas as to why and what I might do to fix it?
I've set up a little demonstration of the problem here:

http://www.frostjedi.com/terra/dev/test.html

It's set up to render in quirks mode to demonstrate that it works in
that mode. just remove the <?xml version=whateve r> line to force it
into strict mode, and to see the problem in IE6.
Anyway, like I said, any help would be appreciated - thanks! :)

Jul 21 '05 #1
3 6120
yawnmoth <te*******@yaho o.com> wrote:
I'm trying to center list elements in a webpage I'm working on,

text-align: center;
and
setting margin-left to auto for ol (or ul) seems to prevent the
number
(or bullet) from displaying in IE6 (strict mode) and Opera7 (it works
fine in Firefox).


list-style-type: none;
Jul 21 '05 #2
Neal <ne*****@yahoo. com> wrote:
I'm trying to center list elements in a webpage I'm working on,


text-align: center;


That would work for some definition of "centering list elements", but
perhaps not for the intended one. It centers each text line inside the
block, separately, not the block as a whole (on conforming browsers)
and
setting margin-left to auto for ol (or ul) seems to prevent the
number (or bullet) from displaying in IE6 (strict mode) and Opera7 (it
works fine in Firefox).


list-style-type: none;


But presumably the OP does not _want_ to prevent the numbers.

An ol or ul element occupies the entire available width by default. The
browser defaults contain some left margin, where the numbers or bullets
will appear (on some browsers) and which is extracted from the available
width. If you just set margin-left: auto, you set the margin to zero.

Unfortunately, even if you set a specific width (say width: 8em) for the
ol or ul element and then left and right margin to auto, at least IE will
omit the numbers or bullets.

A simple workaround: wrap the list inside a div:

<div class="center">
<ol>...</ol>
</div>

with

div.center { width: 8em;
margin: 0 auto; }

replacing 8em by whatever you wish to set the width to.

If the list items are short, you might want to make the width "as wide as
needed". I'm afraid there's no simple way to do that in CSS as currently
defined and implemented. The pragmatic approach is to use HTML: put the
list inside the cell of a single-cell table and use <table align="center"> .

Whether the result is (in either case) really centered depends on what you
mean by centering. The list element's box is centered (you can see what
that box really is by setting a border for the ol or ul element), and
inside that box, there's a fairly wide part on the left reserved for the
numbers or bullets. So looking at the list _content_, or even looking at
the content plus the visible markers, it doesn't look quite centered but
appears somewhat to the right of the center.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 21 '05 #3

Jukka K. Korpela wrote:
Neal <ne*****@yahoo. com> wrote:

<snip>

That would work for some definition of "centering list elements", but perhaps not for the intended one. It centers each text line inside the block, separately, not the block as a whole (on conforming browsers)
yup - text-align: center does indeed not produce the effect that i
want.
<snip>

A simple workaround: wrap the list inside a div:

<div class="center">
<ol>...</ol>
</div>

with

div.center { width: 8em;
margin: 0 auto; }

replacing 8em by whatever you wish to set the width to.

that worked - thanks for the suggestion :)

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
15031
by: Jeff Thies | last post by:
I have a series of blocks that are float left that I need centered on the page. <div class="center" align="center"> <div style="width: 100 px;float: left">thumbnail 1</div> <div style="width: 100 px;float: left">thumbnail 2</div> <div style="width: 100 px;float: left">thumbnail 3</div> </div>
3
7355
by: Jonah Bishop | last post by:
I have a puzzling problem with centering text, and I'm hoping that someone here can help me out. First of all, let me state that I am using XHTML 1.0 Strict and CSS for all layout purposes (no tables). My website consists of a few, simple parts: a "container" DIV which is centered and 750 pixels wide, a "sidebar" DIV which can be found along the left side of the container, and a "content" DIV which fills up what's left of the right part of...
9
7237
by: Pierre Jelenc | last post by:
Is there a way to center (horizontally) a UL list of unknown width? I can put it in a DIV that's centered with "margin-left: auto; margin-right: auto;" but I then have to specify a width; otherwise the auto values get set to 0 and there is no centering. The list is generated dynamically, and there is no way to tell in advance how long each item is going to be. Alternatively, is there a good formula to determine with a reasonable...
3
4634
by: CMAR | last post by:
To center my <div>, I am currently using something like <div id="navcontainer" align="center"> This centers fine, but is deprecated code. I have seen these two solutions recommended. 1) body { text-align: center; min-width: 500px;
6
3149
by: Abs | last post by:
Hi! I'm trying to center horizontally the thumbnails at the top of the following page: http://project.fotografist.com/photos.php?p_idgal=1 Like the image at the center. I've tried different CSS things on different elements but I can't get it to work as I want. Any
2
1887
by: Gnolen | last post by:
Hi again, Last time my server was down(as for many others I have heard), but now it is online again! I would be really really happy if someone could take a look at my problem a bit. I now have two problems...It is the difference between IE and FF.. Problem #1.
3
4211
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a top level <divthen I can place it with CSS attribute 'left:', but this is a fixed offset. Is it possible to have a <divcentered in the browser window? 2. Verticle centering in <div>
5
4824
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up doing this demo with tables. The main problems are the vertical centering of the info area, and of the text inside the squares.
4
4071
by: SAL | last post by:
Hello, is there a way to menu control dynamically center itself horizontally on a page? I have placed a menu control in a panel control (no ajax) and would like it to center itself. Depending on whose logged in, the menu, or course, displays different items, sometimes just two items, other times many more. If all menu items are displaying, centering is not a problem but when only two items are displayed, the menu appears on the left hand...
0
8979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8818
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9522
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9307
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.