[英]I am having some problems with my css and html file
This is my html code:这是我的 html 代码:
<html>
<head>
<style rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"></style>
</head>
<body>
<h2 align="centre">Hello!</h2>
<h1>Hello Again!</h1>
<p>this is a paragraph!</p>
</body>
</html>
this is css code:这是 css 代码:
body {
background: #fafafa;
color: red;
}
header {
color: blue
}
this is python code:这是 python 代码:
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/')
@app.route('/home')
def home():
return render_template("base.html")
if __name__ == "__main__":
app.run(debug=True)
just one url but its still not working i am not a html or css "expert" so i need some help, and i dont have any friends so stackoverflow was the only option只有一个 url 但它仍然无法正常工作
i also saw many people use <link>
tag instead of <style>
idk the difference and google is showing something else, any help would be appriciated!我还看到很多人使用
<link>
标签而不是<style>
idk 差异和谷歌正在展示其他东西,任何帮助都会得到帮助!
Here, I Sorted The Linkings Between Files...在这里,我对文件之间的链接进行了排序......
This Is The Required Folder Structure这是必需的文件夹结构
Here Is The main.css ,
这里是main.css ,
body {
background: #fafafa;
color: red;
}
header {
color: blue;
}
Here Is The base.html ,
这里是base.html ,
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"></link>
</head>
<body>
<h2 style="text-align: center;">Hello!</h2>
<h1>Hello Again!</h1>
<p>this is a paragraph!</p>
</body>
</html>
Here is app.py ,
这是app.py ,
from flask import Flask
from flask import render_template
# from flask import request
app = Flask(__name__, static_url_path='/static')
@app.route('/')
# @app.route('/home')
def home():
return render_template("base.html")
if __name__ == "__main__":
app.run(debug=True)
I don't know python, but why are you trying to get your css file using 'href' tag when you can use 'src' like this我不知道 python,但是当您可以像这样使用“src”时,为什么要尝试使用“href”标签获取 css 文件
<head>
<style rel="stylesheet" type="text/css" src="yourfile.css"></style>
</head>
where src can be absolute path to your file ('c:/yourproject/yourfile.css') or, better, relative path so if you have html and css in the same path you can simply use your css file name?其中 src 可以是文件的绝对路径('c:/yourproject/yourfile.css'),或者更好的是相对路径,所以如果你在同一路径中有 html 和 css,你可以简单地使用你的 ZC7A628CBA22E28EB6AE7BA 文件名?
To include an external stylesheet, you can use <link rel="stylesheet" href="styles.css">
where styles.css is the name of the stylesheet.要包含外部样式表,您可以使用
<link rel="stylesheet" href="styles.css">
其中 styles.css 是样式表的名称。 This should appear within the <head>
tags.这应该出现在
<head>
标记中。 The <style>
tag can be used for internal styles such as: <style>
标签可用于内部 styles 如:
<style>
body {
background: #fafafa;
color: red;
}
header {
color: blue
}
</style>
in your HTML.在您的 HTML 中。 w3schools has a page explaining the different ways to include CSS.
w3schools有一个页面解释了包含 CSS 的不同方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.