为什么我的图像不在我的DIV中心?

问题描述 投票:0回答:5

我必须承认,我对HTML并不多,但我正在努力学习。我有一个以DIV为中心的图像,但它没有真正水平居中。它的左边缘是中心的位置,如下所示:

[----------|----------]

[---------- | image--]

[----------|----------]

怎么办,怎么办....

编辑一些代码:

<style>
#Outer {
position:relative;
height:100%;
width:100%;
text-align: center;
}

#Picture {
position:fixed;
top: 30%;

}
</style>

此外,我垂直和水平居中。垂直工作得很好。

html html5-video center centering
5个回答
0
投票

您可以尝试将位置更改为相对位置。 (见http://jsfiddle.net/VLCqz/1/

至于......的原因


0
投票

这可能有几个原因,请发布您的html和css代码以获得更好的答案。

应该起作用的是将parent text-align属性设置为css中的center。 (see demo


0
投票

我也只是学习HTML,但我发现使用类似的东西

#picture
{
    margin-left:auto;
    margin-right:auto;
}

会得到div或者风格在父div中间的任何东西

希望能帮助到你


0
投票

在图像上设置宽度,然后将图像上的边距设置为0px auto。

<!-- Your HTML -->
<img src="path_to_image.jpg" alt="set alternate text" id="img_id" />

/* Your CSS: */
#img_id {
width: set the width of the image in pixels here (i.e. 250px);
margin: 0px auto;
}

0
投票

你可以像这样简单地做。 :)

<div style="margin:auto;">
      <img src="" id="" />
</div>
© www.soinside.com 2019 - 2024. All rights reserved.