我试图将位于一个 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/