0

我正在尝试跟随 Colt Steele 的课程,但由于某种原因,我的背景图片不会出现。我已经检查了所有内容,但我被卡住了。我尝试在样式标签中编写并在 html 中插入背景,而不是像他那样创建一个单独的 css 文件,但它不起作用。因此,我尝试只制作一个单独的 css 文件,到目前为止我更喜欢它。请让我知道我能做什么。谢谢!

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" type="text/css" href="app3.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

<style>
    #header {
        background-image: url("imgs/header.jpeg");
    }
</style>

    <title>Pattern</title>
</head>

<body>
    <nav class="navbar bg-dark navbar-dark">
        <div class="container">
            <a href="" class="navbar-brand">Quarantine Pal</a>
        </div>
    </nav>

    <section id="header" class="jumbotron text-center">
        <h1 class="display-3">Blog</h1>
        <p class="lead">Lorem ipsum</p>
        <a href="" class="btn btn-primary">Do Something</a>
        <a href="" class="btn btn-success">Another Thing</a>
    </section>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

</body>

</html>

CSS

#header {
    background-image: url(https://images.unsplash.com/photo-1564667005686-cce951e72bd0?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3150&q=80) !important;
}
4

1 回答 1

0

您的 URL 需要是一个字符串,即您需要在它的每一侧添加一个撇号 (')(' https://images.unsplash ...'):

#header {
    background-image:  url('https://images.unsplash.com/photo-1564667005686-cce951e72bd0?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3150&q=80') !important;
}
于 2020-05-16T04:10:31.557 回答