【问题标题】:Background Image Not Showing In Header背景图像未显示在标题中
【发布时间】:2015-05-06 02:51:25
【问题描述】:

CSS 背景图片未显示。这是我用于标题部分的手写笔文件:

.header {
  height 50vh
  border-bottom 5px solid #34495E
  background url(img/head.png) no-repeat center center fixed
  background-size cover
}
.nav {
  display flex
  align-items center
  justify-content flex-end
  padding 1em
  background rgba(0,0,0,0.5)
  position fixed
  top 0
  left 0
  width 100%
  z-index 5
}
.nav-item {
  list-style none
  display inline
  padding 1em
}
a {
  text-decoration none
  color #ececec
  transition 1s
  padding-right 1em
}
a:hover {
  color darken(#ececec, 25%)
  text-decoration underline
}
.space {
  content " "
  height 3.0625em
}

这是它的样子:

这是作为标题背景的图像(其中包含 Darcey Mckelvey 的白色部分):

【问题讨论】:

  • URL 工作正常,一切设置正确,我对此进行了测试。
  • 您能提供一个jsfiddle.net 吗?
  • @DavidAnderton 我不能把它用玉石和手写笔写成,要花很多力气来转换。
  • img 文件夹是否与 css 文件位于同一位置,因为您拥有的路径是相对于 css 文件的位置的。通常的设置需要路径 ../img/head.png
  • 好的达西谢谢你的回复

标签: html css pug stylus


【解决方案1】:

删除标题类的高度。

   .header {
   border-bottom: 5px solid #34495E;
   background: url('img/head.png') no-repeat center center fixed;
   background-size: cover;
   }

【讨论】:

  • 出于某种奇怪的原因,我把高度拿走了,但高度保持不变,因此什么也没发生。图片仍然没有显示。
  • 这很奇怪。它在 jsFiddle 中运行良好。 jsfiddle.net/5ajp38vm
  • 我发现我在标题顶部有一个潜水,我没有添加到上面的代码 sn-p 将它向下推。
【解决方案2】:

您是否尝试在 .header 中添加宽度?说:

.header{
    width:100%
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2019-02-11
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多