html - 主体填充未应用于背景图像

标签 html css twitter-bootstrap

我正在为我的 body 标签做这样的填充,因为我使用的是固定顶部的导航栏。我希望导航栏始终位于顶部。

body {
   padding-top: 70px;
}

现在我想给正文添加一个背景图片,并希望它覆盖整个屏幕。所以我这样做。

body {
   background: url(background.jpg);
   background-size: cover;
}

但问题是导航栏覆盖了部分图像,70 像素的内边距不适用于背景图像。请帮忙解决这个问题。

最佳答案

使用 background-position

中可用的偏移量将背景向下定位 70px

Background-Position @ MDN

body {
  background-image: url(http://www.fillmurray.com/g/200/300);
  background-position: top 70px center;
  background-size: cover;
  background-repeat: no-repeat;
}

关于html - 主体填充未应用于背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39172191/

相关文章:

jquery 移动文本覆盖文本奇怪的按钮

javascript - CSS 的 SEO 隐藏 JS 淡入

html - 上传前批量替换数百个html文件的div内容

javascript - 如何同时旋转多根弦

jquery - 将这个 CarouFredSel 旋转木马居中

jquery - Twitter bootstrap 附加无限滚动和 window.resize

html - "icon-bar"在 twitter bootstrap 导航栏

django - 如何在 Django 中使用 Font-awesome 的星级?

javascript - 发送消息后弹出不起作用

html - 下拉菜单显示不正确