我有一个 ID 为 leftheader
的 div,我想在 div 的中心放置一张图片。我正在尝试这个 css
#leftheader {
float: left;
width: 28%;
height: 140px;
margin: auto;
}
#leftheader img {
/*padding-left: 80px;*/
}
当我使用 padding-left: 80px;
时,我得到了图像的中心对齐。但是由于我在 leftheader
的宽度中使用了 %
,所以我不想使用 像素值
。谁能给我推荐一个更通用的 css 布局。
最佳答案
如果你使用text-align :center;您的图像应在 div 中居中。
#leftheader {
float: left;
width: 28%;
height: 140px;
margin: auto;
text-align: center;
}
关于css - 将图像放在 div 的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13802379/