tags:

views:

1009

answers:

3

Greetings, I'm trying to create a pagination panel for one of my lists and want to make it centered. Currently it looks like:

<div class="panel">
  <div class="page">1</div>
  <div class="page">2</div>
  <div class="page">3</div>
</div>

So I'm basically trying to make all of the "page" div elements go to the center of "panel" container, like this:

_____________________________
|           1 2 3            |
------------------------------

Is there a way to implement that without knowing the width that "page" elements need (there could be 3 or 9 pages and both situations should be handled properly).

Thanks in advance.

A: 

do you have to use divs for the numbers?

i would replace those divs with spans instead and then apply a text-align:center to the outter div (.panel)

Wayne Austin
+3  A: 

Is there any reason you want the pages to be <div>s? If you make them a <span class='page'> (which is more semantically correct imho) and apply text-align: center; to the panel you get the effect you want. Otherwise you could do display: inline; on the pages, but for that you might as well go to <span>

Paolo Bergantino
+1 - the same points as everyone else, but well explained too
annakata
If only display: inline-block; worked on all browsers.
GoodEnough
Well, after digging a little on display: inline-block, I've found a page describing a hack to make inline-block cross-browser compatible: http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/ . Looks like it should make the trick.
Max
A: 

As this is a list of numbers, you shoud consider placing them in a list to be semantically correct. Shove them into a UL, style that with CSS and you're golden.

Like so perhaps:

<div class="panel">
 <ul>
   <li><a href="#">1</a></li>
   <li><a href="#">2</a></li>
   <li><a href="#">3</a></li>
 </ul>
</div>

And style in CSS as this:

.panel{text-align:center; }
.panel ul{list-style-type:none; margin:0 auto; padding:0; overflow:hidden; }
.panel li{display:inline; }
.panel li a{padding:5px; margin:0;}

Play around with the padding and margins. Always a good idea to add some fatness to your links when they're used in pagination, tabs and menus.

Tested in Opera 9, FF3, IE6, Chrome

random