[英]I can't set the background using CSS in my Flask app
I'm creating a web app with Flask. 我正在使用Flask创建一个Web应用程序。 I created a style.css file and was able to use it successfully to specify some table attributes.
我创建了一个style.css文件,并能够成功使用它指定一些表属性。 But when I try to use code from CSS Tricks to add a background image for my landing page, the image fails to show.
但是,当我尝试使用CSS Tricks中的代码为目标网页添加背景图片时,该图片无法显示。
CSS: CSS:
html {
/* Source: https://css-tricks.com/perfect-full-page-background-image/ */
background: url(static/landing_page.jpeg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I created a simple test.html file that uses the same CSS and it worked (the image showed up, and was scaled properly). 我创建了一个简单的test.html文件,该文件使用相同的CSS并可以正常工作(图像显示出来,并且已正确缩放)。
Using built in function url_for you can get this inside jinja html, just place this on your css style 使用内置函数url_for,您可以在jinja html中获取此代码,只需将其放在您的CSS样式中
url("{{url_for('static',filename="landing_page.jpg")}}");
In general when you refer to a static file , a common practice is to target it through url_for function. 通常,当您引用静态文件时,通常的做法是通过url_for函数将其定位。
该URL必须是url(landing_page.jpeg)
,而不是url(static/landing_page.jpeg)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.