html - 无法正确定位背景图像

标签 html css background-image

我正在尝试定位背景图像,使其保持比例/适应屏幕尺寸,并且不会 float 到导航栏中。我使用的CSS是:

#apology{
background-image:url('http://i.imgur.com/jkXf9IE.png');
width:50%;
margin:0 auto;


background-position:50% 50%;
background-size:cover;


position:fixed;
left:10%;
top:10%;
right:10%;
bottom:10%; 

}

这是一个 fiddle background-image

最佳答案

更新顶部的css,用像素而不是百分比修复它

#apology {
    background-image: url(http://i.imgur.com/jkXf9IE.png);
    width: 50%;
    margin: 0 auto;
    background-position: 50% 50%;
    background-size: cover;
    position: fixed;
    left: 10%;
    top: 52px; //update this
    right: 10%;
    bottom: 10%;
}

正在工作 jsfiddle

关于html - 无法正确定位背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42877382/

相关文章:

javascript - 层叠两个 HTML 组件

javascript - Vue JS 设置要选择的填充选择中的第一项

css - 强制浏览器忽略包装器中的溢出元素

css - 如何将背景设置为可变高度的 div?

html - 使用 CSS 从段落的第二行开始缩进

html - 我怎样才能制作一个可调整的 table ,边单元格的最小宽度和可调整的中心单元格

html - 在windows操作系统下建网站,在linux下变形。我如何解决它

javascript - 弹出背景不覆盖导航栏

iphone - iPad 和 iPhone : full page background image shows cut off/screen shot link included

css - 如何向背景图像添加颜色叠加层?