HTML CSS 图像不会居中?

标签 html css image

我试图将位于一个 div 内的图像居中,然后该图像位于另一个 div 内。别担心,我会发布一些代码,这样你们就能明白我到底在说什么。

HTML:

<div id="container">

    <div id="featureimage"  style="width: 845px">
        <img src="Stylesheets/images/globkey.jpg" alt="" />
    </div>

</div>

CSS:

body {
    background-color: #383838;
    margin: 0; padding: 0;
    font-size: small;
    color: #383838;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    }
* html body {
    font-size: x-small; /* for IE5/Win */
    font-size: small; /* for other IE versions */
    }

img {
    border-style: none;
}



/* Conatiner */ 
#container {
    background-color: #fff;
    width: 845px;
    margin: 0 auto;
    overflow: hidden;
    }


#featureimage{
    width: 620px;
    padding: 0 0 0 15px;
    margin: 20px 0;

/* I have also tried without padding and no margin!*/
    }   

#featureimage img{
    margin-left:50%;
    margin-right:50%;
    width:360px;
    height:360px;
    }

我在这里没有想法!一直在这!

感谢您的帮助,

埃文

最佳答案

图片是行内元素,要居中,可以使用text-align: center; 或者设置为display: block 并设置margin: 0 auto ;

关于HTML CSS 图像不会居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7086281/

相关文章:

asp.net - @font-face 对三种不同的格式根本不起作用

java - 分析图像颜色的最佳方法是什么(Java)?

html - 制作面包屑...不像字面上制作面包屑那么容易,我怎样才能让文字在里面?

html - 为什么我不能在 HTML5 数字字段中输入 500?

html - DIV 元素未正确放置在图像旁边

html - 元素之间的CSS伪元素

jquery - jquery中的动画问题

image - 如何在 OpenCV 中使用 Adob​​e RGB 色彩空间读取 jpeg 图像?

python - 在 Pygame 中比较图像(不是逐像素比较)

javascript - 使用javascript获取下拉框值?