图像的垂直和水平对准图像、水平

2023-09-11 07:57:55 作者:是你讓俄無知到相信奇跡。

我有一个占位符(在建)网站,仅保留一个具有标志形象。 0汽车:我horizo​​ntically与边缘排列。 但我怎么知道另外的水平对齐图像。 或者用一句:我如何完全滤清图片

I have a placeholder (under construction) site which holds only one image with the logo. I horizontically aligned with margin: 0 auto. But how do I know additionally horizontal align the image. Or with one sentence: How do I fully centrate an image.

看这里看直播:小提琴

问候, 博德

编辑: 为1:2(高度与宽度)图像用:

For 1:2 (height to width) images use:

#wrapper img
{
    position: absolute;
    top: 50%;
    left: 50%;
    width: 799px;
    height: 404px;
    margin: -202px -399px 0;
    border: 1px solid black;
}

像在链接的主题:)

like in the linked thread :)

感谢您的帮助

推荐答案

URM ..你有没有试过?

Urm.. Have you tried ?

<div class='placeholder'>
   <img src='../images/myimage'>
</div>

和的CSS,该标记

.placeholder
{
position : absolute;
top : 50%;
left : 50%;
width : 200px; /* Width of the image in question */
height : 200px;/* height of the image in question */
margin : -100px 0px 0px -100px;
}

这应该把你的图像与页面的中心。

This should bring your image to the very center of the page.