使用Flask-Bootstrap模板时,引入自定义css的办法

在使用Flask-Bootstrap模板的html中加入以下代码,即可引入自定义css

{% block styles %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
{% endblock %}

我的css存放于/static/styles.css, 所以href的地址为"{{ url_for(‘static’, filename=‘styles.css’) }}"。你们插入的时候换成自己的css文件存放位置即可。

更详细的例子:

{% extends "bootstrap/base.html" %}

<!-- 引入自定义css-->
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
{% endblock %}

<!-- 网站标题 -->
{% block title %}Flask{% endblock %}

另外提示:自定义的css文件中直接定义class即可,例如:

.self-navbar-brand-text {
    font-family: cursive;
    font-weight: bold;
    font-size: 22px;
}

 

posted @ 2022-08-24 13:57  花小心  阅读(240)  评论(0)    收藏  举报