Css 我不知道';我不知道为什么我的照片是';不要浮到中心

Css 我不知道';我不知道为什么我的照片是';不要浮到中心,css,html,Css,Html,我需要将图像放在中间,但这不是出于某种原因。我的HTML代码: <div class="face-img"> <img id="profile-img" src="http://host2post.com/server13/photos/jI7X5kXAIEk_4M~/1680x1050-lake-tahoe-california-desktop-wallpaper-background.jpg" /> </div> 作为一个例子,文本对齐属性需要位

我需要将图像放在中间,但这不是出于某种原因。
我的HTML代码:

<div class="face-img">
    <img id="profile-img" src="http://host2post.com/server13/photos/jI7X5kXAIEk_4M~/1680x1050-lake-tahoe-california-desktop-wallpaper-background.jpg" />
</div>

作为一个例子,
文本对齐
属性需要位于父元素上:

描述内联内容(如文本)如何在其父块元素中对齐。文本对齐不控制块元素本身的对齐,只控制其内联内容

由于默认情况下
img
元素是
inline
text align:center
将有效地将子
img
元素置于父元素的中心

在本例中,您只需要删除
display:inline块
,因为这会导致父元素具有相同的宽度(这意味着父元素与子元素具有相同的宽度,因此,不可见居中)


另外,
center
不是的有效值。

您需要删除
display:inline块
,并将
text align:center
添加到
face img
类。

一些简化的代码,使用边距自动解决方案。它假设你不需要我遗漏的其他东西

在IMG的左右边缘使用AUTO,PIC集中在页面中间。边距:0自动0自动

小提琴示例

css

html


以下css作品:

.face-img {
  text-align: center;
}

#profile-img {
  height: 200px;
  width: 200px;
  border-radius: 50%;
}
以下工作:

.face-img{
   width:200px;
   margin-left:auto;
   margin-right:auto;
}
#profile-img{
  height: 200px;
  width: 200px;
  border-radius: 50%;  
}

设置div的宽度,并将左右边距设置为自动。

float:center
不存在@BrendonBaughn嗯,它在我链接到的一个中起作用-我必须去掉“display:inline block”lol谢谢you@BrendonBaughn赞成。。我在回答中是这么说的。我很高兴我帮了忙!:)
.profile-img {
    display: block;
    margin: 0px auto 0px auto;
    height: 200px;    width: 200px;
    border-radius: 50%;
}
<img class="profile-img" src="">
.face-img {
  text-align: center;
}

#profile-img {
  height: 200px;
  width: 200px;
  border-radius: 50%;
}
.face-img{
   width:200px;
   margin-left:auto;
   margin-right:auto;
}
#profile-img{
  height: 200px;
  width: 200px;
  border-radius: 50%;  
}