1

我目前正在尝试设计我的烧瓶应用程序。整个想法是有一个书籍背景,因此让它看起来像一个图书馆,因为该应用程序基于书评并且可能在未来购买。

我通过 layout.html 模板中的以下 html 代码链接了 style.css:

  <link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}">

我已经将文件和文件夹结构设置为:

 application.py
 venv/
 templates  /  layout.html
 templates  /  login.html
 static  /  styles.css
 static  /  books.jpg

到目前为止,我已经做了以下尝试来解决这个问题:

1 在检查>网络中禁用浏览器缓存(没有改变任何东西)

2 尝试直接在页面内应用样式。

  1. 我发现解决不更新问题的唯一方法是使用 cntl + f5 重新加载

我想要一些关于如何让 CSS 以预期方式运行以及在通过浏览器重新加载时重新加载而无需使用 ctrl+f5 方法的建议。

最好的方法是什么?

这是 layout.html 的完整 CSS


    /* Reset page */
    /* http://meyerweb.com/eric/tools/css/reset/ 
       v2.0 | 20110126
       License: none (public domain)
    */
    
    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td,
    article, aside, canvas, details, embed, 
    figure, figcaption, footer, header, hgroup, 
    menu, nav, output, ruby, section, summary,
    time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 100%;
        font: inherit;
        vertical-align: baseline;
    }
    /* HTML5 display-role reset for older browsers */
    article, aside, details, figcaption, figure, 
    footer, header, hgroup, menu, nav, section {
        display: block;
    }
    body {
        line-height: 1;
    }
    ol, ul {
        list-style: none;
    }
    blockquote, q {
        quotes: none;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
        content: '';
        content: none;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    
    body{
        width:100%;
        background-image: url("books.jpg") no-repeat center fixed;
        background-size: cover;
    }
    #content{
        background-color: #252629;
        text-align: center;
        height: 100%;
        padding-left:5%;
        padding-right:5%;
        margin-left: 15%;
        margin-right: 15%;
        margin-top:10%;
    }
    
    /*nav bar*/
    #nav-bar{
        height: 10%;
        background-color:#252629;
        opacity: 85%;
    }
    ul.nav{
        line-style: None;
        position: absolute;
        width: 100%;
        height: 100%;
    }
    li.nav{
        width:33%;
        display: inline-block;
        float: left;
    }

以下是 layout.html 的 HTML 代码,以防我在其中做错了什么:

    <!DOCTYPE html>
    <html lang="en">
        <Head>
            <link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}">
            <script src="{{url_for('static', filename='script.js')}}"></script>
            <title>{%block title%}{%endblock%}</title>
            {%block head%}{%endblock%}
        </Head>
        <body>
            <div id="nav-bar">
                <ul class="nav">
                    {% if session.user_id %}
                        <li class="nav">
                            <form action="{{url_for('api')}}" method="post">
                                <input type="text" name="api" placeholder="Enter isbn for API"> 
                                <button id="api">API Search</button>
                            </form>
                        </li>
                            <form action="{{url_for('search')}}" method="post">
                                <input type="text" name="search" placeholder="Title, Author, or ISBN">
                                <button id="search">Search</button>
                            </form>
                        </li>
                        <li class="nav"><button id="logout">Log Out</button></li>
                    {% else %}
                        <li class="nav"><button id="login">Log In</button></li>
                        <li class="nav"><button id="Register">Register</button></li>
                    {% endif %}
                </ul>
            </div>
            <div id="content">
                {% block content%}
                {%endblock%}
            </div>
        </body>
    </html>

我没有包含 application.py,因为它现在只是返回 render_template('index.html'),因为我首先专注于设计。

如前所述,我希望获得一些帮助,以使 CSS 正常运行并在不需要 ctrl+f5 方法的情况下使用浏览器重新加载,以及如何在不放大的情况下让大量背景图像填充窗口。

4

2 回答 2

1

因为你的语法不正确。如果你想用简写写背景属性,你必须使用background:属性,而不是background-image:

所以,你可以这样使用:

background: url("books.jpg") center/cover no-repeat  fixed;

或者

background-image: url("books.jpg");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
于 2020-06-24T09:24:16.170 回答
0

它将仅显示更改端口并在 background-image=url() 中指定完整路径,例如,如果我的图像是静态的,那么我将在图像文件夹中执行此url(../images/img. jpg); . 如果仍然无法正常工作,请清除浏览器历史记录或重新启动计算机。

于 2021-04-06T14:36:06.807 回答