473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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=whatever> 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 6095
yawnmoth <te*******@yahoo.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
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:...
3
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...
9
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...
3
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) ...
6
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...
2
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...
3
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...
5
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.