Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a css equivalent to 'align="center"'?

Tags:

I tried:

margin-left: auto;
margin-right: auto;

But it doesn't center the elements in my table cells. I have a combination of text and <span> elements in the <td>s.

Once I set 'align="center"' in any of the <td> elements, it does center.

How do I achieve this in the stylesheet?

Btw, when I do text-align: center that works for text. But not for other elements like <span>s.

Edit:

The span has the following class, if that affects the alignment issue:

.dot {
    display: block;
    width: 10px;
    height: 10px;
    background: #333;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -khtml-border-radius: 5px;
}
like image 830
marcamillion Avatar asked Sep 27 '10 01:09

marcamillion


People also ask

How do you make an alignment center in CSS?

To just center the text inside an element, use text-align: center; This text is centered.

How do I center my position in CSS?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

Is Align Center deprecated?

The CENTER element is deprecated because basically a it's a purely presentational tag rather than structural and is similar to shorthand for 'DIV align=center' which is better handled via CSS.


1 Answers

margin:0 auto; will work on

  • block level non-floated, static/relative positioned elements with an explicit width set
  • intrinsic width elements like images/objects/tables

text-align:center will work on

  • inline/inline-blocks

For your situation you can probably do..

#container { text-align:center; }
#container span.block-level-spans { margin: 0 auto; }

or make the spans inside inline-block instead of block.

EDIT:

Inline-block: This value causes an element to generate a block box, which itself is flowed as a single inline box, similar to a replaced element. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an inline replaced element.

like image 82
meder omuraliev Avatar answered Sep 21 '22 06:09

meder omuraliev