CSS:
html,body{
height: 100%;
}
img{
position: relative;
top: 40%;
float:left;
}
使用浮动:左;在 img 类中。这将解决问题,图像将显示在预期位置(距离屏幕顶部 40%)。
当该值以百分比形式提供时,它是相对于包含块的高度。
但是
img
没有包含块。你可以添加position: absolute;
到img.
CSS:
img{
position: absolute;
top: 40%;
}
这可以帮助你... 我的建议是使用 px 而不是 %。它工作正常。
html,body{
height: 100%;
}
img{
position: relative;
top: 40px;
}
为 p 标签添加 float:left
新的CSS,
html,body{
height: 100%;
}
img{
position: relative;
top: 40%;
}
p {
float:left
}