Center a horizontal div

0

How to center a horizontal DIV without knowing its width.

Example:

Previous - 1, 2, 3, 4 - Next

    
asked by anonymous 07.08.2014 / 13:52

2 answers

0

I use the techniques that are listed in this article: link

They were very useful to me.

    
07.08.2014 / 17:39
2

A quick solution, provided you do not worry about semantics, would be to use the display: table attribute instead of display: block in your divs, like this:

<div id="paginador-wrapper">
    <div id="paginador-container">
        <!-- aqui vai a saída do seu código... -->
    </div>
</div>

In CSS, just apply these styles:

#paginador-wrapper {
    display: table;
    width: 100%;
}
#paginador-container {
    display:table-cell;
    text-align:center;
    vertical-align:middle;
}

Display as table and table cell accepts centering in the same way as a regular table. It is not the most beautiful solution in the world, but it is still much better than working with placements and fluctuations.

Note: according to w3scholls , the "inline-table" values, "table-caption", "table-cell", "table-column", "table-column-group", "table-row", and "table-row-group" do not work in IE7 and earlier and in IE8 you must use "! DOCTYPE" in html.

    
07.08.2014 / 14:23