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;
}
To just center the text inside an element, use text-align: center; This text is centered.
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.
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.
margin:0 auto;
will work on
text-align:center
will work on
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With