Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float: center doesn't work?

I'm doing my first Tumblr theme using a tutorial, I'm a total newbie at this.

.metadata a {
display: inline-block;
float: center;
margin-left: 2%;
}

I want the posts to be centered, but the only things that work are float: left and float: right

What should I do ? Please explain clearly because as I said, I'm a total newbie, and I'm not a native English speaker.

like image 350
Pokoro Avatar asked Jul 06 '26 03:07

Pokoro


2 Answers

You can only float left or right, so float is not an option here.

Add text-align: center to the parent element of the a-tag. That will center not only text, but also other inline and inline-block elements, like yours.

Another way to center element, is to give them display: block; margin 0 auto. The 'automatic' left and right margins cause the element to be centered. It's a common trick to center elements, but it works on block elements only (or elements with display: block). That also means that you have to specify a width, because if you don't, the block element will consume 100% of the parent width.

I think in your case, an explicit width isn't an option, so text-align will be the best option.

like image 103
GolezTrol Avatar answered Jul 11 '26 10:07

GolezTrol


Sorry, but there is no float: center;. Use margin: 0 auto; to center block level elements and text-align: center; for inline.

like image 35
jsblaisdell Avatar answered Jul 11 '26 11:07

jsblaisdell