浮动:中心不工作? [英] Float: center doesn't work?

查看:103
本文介绍了浮动:中心不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用教程完成我的第一个Tumblr主题,我是一个新手。

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%;
}

我想让帖子居中,但只有工作是浮动的:left and float:right

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.

推荐答案

您只能向左或向右浮动,因此此处的浮动不是选项。

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

添加 text-align:center 到a-tag的父元素。

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.

中心元素的另一种方法是给它们 display:block; margin 0 auto 。 自动左右边距使元素居中。这是一个常见的中心元素的伎俩,但它只适用于块元素(或具有 display:block 的元素)。这也意味着你必须指定一个宽度,因为如果你不,块元素将消耗100%的父宽度。

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.

我认为在你的情况下,显式宽度不是一个选项,因此text-align将是最好的选择。

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

这篇关于浮动:中心不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆