Html css图像定位中心
我有定位图像的问题Html css图像定位中心,html,css,css-position,Html,Css,Css Position,我有定位图像的问题 <div class="foto img-thumbnail"> <img class="img-thumbnail tengah" src="member/37/foto_profile/profile37.png"> </div> 绿色=天加级 红色=等级foto 我想要div的红色定位中心的图像 当我改变css时,就像 .tengah { left: 50%; top: 50%; position: absolute; } 它
<div class="foto img-thumbnail">
<img class="img-thumbnail tengah" src="member/37/foto_profile/profile37.png">
</div>
绿色=天加级
红色=等级foto
我想要div的红色定位中心的图像
当我改变css时,就像
.tengah {
left: 50%;
top: 50%;
position: absolute;
}
它返回图像的中心
有人能帮我吗
之前谢谢:我想你说的是将.tengah div放在.foto的中心位置 如果是,那么您需要:
.foto {
background-image: url('member/37/foto_profile/large.jpeg');
height: 300px;
background-repeat: no-repeat;
background-size:cover;
background-position:
center center;
width: 100%;
position: relative; /* ADDED */
}
.tengah {
left: 50%;
top: 50%;
position: absolute;
margin-top: -30px; /* ADDED */
margin-left: -30px; /* ADDED */
}
边距是您希望居中的宽度和高度的一半。我想您所说的是将.foto中的.tengah div居中 如果是,那么您需要:
.foto {
background-image: url('member/37/foto_profile/large.jpeg');
height: 300px;
background-repeat: no-repeat;
background-size:cover;
background-position:
center center;
width: 100%;
position: relative; /* ADDED */
}
.tengah {
left: 50%;
top: 50%;
position: absolute;
margin-top: -30px; /* ADDED */
margin-left: -30px; /* ADDED */
}
边距是您希望居中的屏幕宽度和高度的一半。一种更干净的方法可以适应不同大小的屏幕,即通过为.tengah类设置自动左右边距来避免位置:绝对:
.tengah {
position: relative;
margin-left: auto;
margin-right: auto;
top: 50%;
}
此样式类将自动使图像/div居中。如果不使用垂直对齐,则可以根据图像长度稍微调整顶部。适应不同大小屏幕的更干净方法是通过为.tengah类设置自动左右边距来避免位置:绝对:
.tengah {
position: relative;
margin-left: auto;
margin-right: auto;
top: 50%;
}
此样式类将自动使图像/div居中。如果不使用垂直对齐,则顶部可以根据图像长度稍微调整。tengah图像的宽度和高度是否已定义?否,tengah宽度图像60px:60px不确定您到底想要什么?您是要将红色div自身居中,还是将绿色div置于红色div内部居中?tengah图像是否定义了宽度和高度?不,tengah宽度图像60px:60px不确定您到底想要什么?您想将红色div自身居中,还是将绿色div置于红色div内的居中?