元素中的中心块元素 [英] Center block element in element

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

问题描述

我试图使一个块元素(WordPress的标题框,包括图像)居中,但它不会工作。我尝试过:

I'm trying to center a block element (the WordPress caption box, including the image) but it won't work. I've tried:

.imagecenter {
   margin-left: auto;
   margin-right: auto;
   display: block;
}

但它不会工作。我也试过 margin-left:auto; margin-right:auto; 但是也不会工作。有什么我做错了吗?这是W3C文档说的我应该做的。

But it just won't work. I've also tried margin-left: auto; margin-right: auto; but that won't work either. Is there anything I'm doing wrong? This is what the W3C documentation says I should do.

在HTML中看起来像这样(澄清):

It looks like this in the HTML (to clarify):

<div id="content">
........post here......
<div class="wpcaption imagecenter" style="width:225px">
<img src="blah" />
Blah.
</div>
.........post here......
</div>

我无法控制元素的宽度。它由用户设置。用户希望div居中。它不工作。我已查看过文档,但仍然无法正常工作。

I have no control over the width of the element. It's set by the user. The user wants the div to be centered. It's not working. I've looked over documentation but it still won't work.

编辑:我已经完成了自动翻译:自动和自动 - 右:自动。它不工作。

I HAVE ALREADY TRIED MARGIN-LEFT: AUTO AND MARGIN-RIGHT: AUTO. IT DOESN'T WORK.

推荐答案

一般来说,要在中心放置一个div,右边距自动,然后给予div一个宽度:

In general, to position a div in the center, the technique is to make both the left and right margins auto and then give the div a width:

.centerDiv
{
    margin-left:auto;
    margin-right:auto;
    width: XXX px;
}

这篇关于元素中的中心块元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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