【问题标题】:Can't get background image to show for page header无法为页眉显示背景图片
【发布时间】:2022-08-16 20:27:04
【问题描述】:

很抱歉,这与以前提出的问题相似,但我对编码比较陌生,而且我正在把头撞到墙上。

我正在尝试创建一个个人网站,但似乎无法在网页顶部的标题/标题后面显示图像。我知道该位置有效,因为我可以通过 html 使图像独立显示(作为页面顶部的单独图像),但是每当我尝试通过 CSS 添加样式时,它就会停止工作。更令人困惑的是我可以更改背景颜色(通过 id 选择器#header),所以我不确定是什么阻止了背景图像的工作。非常感谢任何帮助。

这些是相关的代码位:

HTML 代码:

 <body>
        <div id=\"header\">
            <div class=\"name\">
            <h1>Author Name</h1>
            </div class=\"name\">\"   
        </div id=\"header\">  

CSS:

h1 {
    margin: 20px;
    text-align: center;
    font-size: 60px;
    font-family: \'Montserrat\', sans-serif;
    font-weight: 900;
  }

 #header {
    background-image: url(https://drive.google.com/uc?export=view&id=1jGtln4lbaCeJ0D6mdY_A1UMKTr2QFOLp);
    width:100%;
    height:auto;
}

  • 不要关闭带有 id 的 html 标签,使用 </div>

标签: html css image background


【解决方案1】:
 #header {
    background: url(https://drive.google.com/uc?export=view&id=1jGtln4lbaCeJ0D6mdY_A1UMKTr2QFOLp) no-repeat center center fixed;
   background-size: cover;
    width:100%;
    height:auto;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2013-08-16
    • 2020-09-11
    相关资源
    最近更新 更多