我已经阅读了有关在 flask 中显示背景图像的其他问题,但没有一个建议的解决方案对我有用,我收到 404 错误(127.0.0.1 - - [22/Feb/2018 15:13:33] “获取/img/showcase.jpeg HTTP/1.1” 404 -)。我要设置为背景的 jpeg 图像位于静态文件夹中,名为 showcase.jpeg。这是我的代码。有什么建议么?这是我的 style.css 的 HTML 链接:
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='style.css')}}">
CSS 文件:
#showcase{
background-image: url({{ url_for ('static', filename = 'showcase.jpeg') }});
height: 100vh;
background-size: cover;
background-position: center;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
padding: 0 20px;
font-weight: bold;
}
最佳答案
CSS 文件被读取为静态文件,因此您不应在 CSS 中使用 url_for 方法。
如果你的文件结构是:
static
-img
-css
使用background-image: url(../img/showcase.jpeg)
关于html - 使用 Flask 的 CSS 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48938957/