使用 Bootstrap 没有出现在 CSS 中的背景图像

伊利

我对 Web 开发还很陌生,并且一直在尝试使用托管在 github 上的 Bootstrap 创建一个网站。我正在使用的引导程序主题有一个标题部分,我试图用背景图像覆盖它(它最初只是纯色),但是图像没有出现。

这是我的代码:HTML - 标题部分:

<header class="masthead" id="banner">
  <div class="container">
    <div class="col-lg-12 text-center">
      <img class="img-fluid" src="img/headshot.png" alt="Headshot">
      <div class="intro-text">
        <span class="name">NAME</span>
        <hr class="star-light">
      </div>
    </div>
  </div>
</header>

CSS:

header.masthead {
  text-align: center;
  color: white; 
  background: #148ABC;}

#banner {
  background-image: url("/img/banner.jpg") no-repeat center; 
  background-size: cover; 
  width: 100%;
  height: 100%; }

"banner.jpg"的背景图像文件位于“img”文件夹中,该文件夹与包含实际 css 文件的“css”文件夹位于同一目录中。我尝试了以下方法:

  • 将 url 更改为“/img/banner.jpg”、“../img/banner.jpg”和“img/banner.jpg”(我认为第一个仍然正确?)
  • 删除 #banner id 并将所有内容单独放在 header.masthead 下的 css 中
  • 删除宽度和高度
  • 仔细检查文件的名称(它是banner.jpg)

我已经为此工作了好几天,所以我对自己感到非常沮丧。谢谢你的帮助!

吉什努VS

只需尝试使用此代码段,我已更改background-imagebackground并删除background color了标题的

header.masthead {
  text-align: center;
  color: white; 
}

#banner {
  background: url("https://www.w3schools.com/css/trolltunga.jpg") center center no-repeat; 
  background-size: cover; 
  width: 100%;
  height: 100%; }
<header class="masthead" id="banner">
  <div class="container">
    <div class="col-lg-12 text-center">
      <img class="img-fluid" src="img/headshot.png" alt="Headshot">
      <div class="intro-text">
        <span class="name">NAME</span>
        <hr class="star-light">
      </div>
    </div>
  </div>
</header>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用CSS模糊没有背景图像的元素

对象没有出现在组件 React Bootstrap/CSS 的中间

在没有单独 CSS 的 Div 中设置背景图像

CSS 没有显示,因为没有明显的原因 <head> 没有出现在 _site 文件夹中

Bootstrap 4:如何在没有 CSS 的情况下包含背景图像

css 文件没有出现在我的实时 github 页面应用程序中

滚动条没有出现在 CSS 的下拉列表中

为什么某些 css 属性没有出现在我的母版页中?

为什么我的 CSS 边框没有出现在 JavaFX gui 中?

为什么CSS3右对齐的背景图像出现在错误的位置?

使用MVC动态将CSS背景图像添加到Bootstrap 4巨型机

使用bootstrap / css根据屏幕尺寸更改背景图像的高度

使用 rvest 抓取网页分页。分页路径没有出现在结构中

React-Bootstrap Modal 的问题没有出现在自定义上下文菜单中

背景图像未使用 CSS 显示

使用javascript更改css背景图像

使用CSS将背景图像居中

使用 Flask 的 CSS 背景图像

使用背景图像的 CSS 宽度转换

使用 css 设置背景图像

背景图像未出现在<span>元素中

背景图像出现在表单输入中

背景图像未出现在XCODE 12中

Bootstrap模态出现在背景下

如何在css3中使用图像集设置背景图像?

网格布局中每个块的背景图像-HTML中没有CSS

有没有办法在 HTML/CSS 中为背景图像留出余量?

CSS初学者:在没有图像透明度的情况下使用渐变背景图像

为什么图片没有出现在背景中