在CSS中居中图像

时间:2017-08-01 13:47:31

标签: html css text flexbox

我的css有问题,我似乎无法居中我的形象,除非我使用填充,我尝试使用flexbox,机智对齐内容,并对齐项目,但它不会工作,我不知道怎么做,不管它不会中心,除非我使用填充。有人可以帮忙吗?

这是迄今为止的代码:

img {
padding: inherit;
margin:auto;
text-align:center;
}

here is the outcome of the webapage

5 个答案:

答案 0 :(得分:3)

试试这个:

img {
  padding: inherit;
  margin:auto;
  width: 200px;
  display: block;
}
<img src="http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg">

答案 1 :(得分:1)

选项1: 设置宽度,以便将边距设置为0 auto

img { width:<image_size> margin: 0 auto }

选项2: 使用块显示并将边距设置为自动

img { display: block; margin:auto; }

答案 2 :(得分:1)

使用

img {
    display: block;
    margin:0 auto;
    text-align:center;
}  

答案 3 :(得分:0)

请尝试将margin-right和marign-left设置为null。

img {
    padding: inherit;
    margin-left: 0;
    margin-right: 0;
    text-align: center;
}

答案 4 :(得分:0)

恢复所有答案:

如果您的图片具有显示块属性,要使图像居中,您需要执行以下操作:

information_schema

如果你的形象&#34;生活&#34;在您的内容中免费,没有展示属性,那么您只需要以 text-align:center 属性为中心。

示例:

img {
    display:block;
    width: 200px; // You need to add a fixed width
    height:auto // Optional but i recommend, in case of you need a proportional redimensioning
    margin:0 auto;
}

我希望它可以帮到你。

相关问题