html - extends - 如何忽略父级上的子级 CSS
问题描述
我想忽略子 CSS(index.html
例如)nevbar.html
我有一个导航栏,'nevbar.html'
我正在使用{% extends 'nevbar.html' %}
其中index.html
还有一个 CSS 文件,index.html
但它也会影响我想要的元素,nevbar.html
因此效果只会发生index.html
在'nevbar.html'
. 代码示例:
a {
background:
linear-gradient(
to bottom, var(--mainColor) 0%,
var(--mainColor) 100%
);
background-position: 0 100%;
background-repeat: repeat-x;
background-size: 4px 4px;
color: #000;
text-decoration: none;
transition: background-size .2s;
}
这是除了index.css
nevbar.html
也使用a
标签
<a href="" class="nav-item nav-link active this-is-navbar">Home</a>
而且对元素index.css
也有影响。nevbar.html
这只是一个我可以为其创建 ID 的示例,index.html
因此 CSS 仅适用于文件中的标签,但我有超过 5 个文件要放入nevbar.html
其中,我无法为所有内容创建 ID。
如果某个标签中有某些东西,也许我可以这样nevbar.html
做
Frontend framework: bootstrap
Backend framework: Flask
code sample
如果你去后端/
@app.route('/')
@login_required
def index():
return render_template('index.html', user=current_user.username, level = int(current_user.level))
index.html
部分
{% extends 'navbar.html' %}
{% block head%}
<title> Main Page </title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/index.css') }}"/>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
{% endblock %}
{% block body%}........
navbar.html
start of the code
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">..... end of the code
</nav>
</div>
{% block body%}{% endblock %}
</body>
</html>
<style>
.bs-example{
margin: 20px;
}
</style>
解决方案
推荐阅读
- ios - iOS App build Rejected :- 位置权限模式警报描述
- email - 在 Gmail 中强制使用新线程
- c - 单词切碎/混合程序
- dependency-injection - 在 IOC 容器中添加新对象,而无需指定每个构造函数参数
- visual-studio-code - 在 Visual Studio 2017 中作为 MAC 代理的等效工具,用于使用 Visual Code 的 Nativescript
- azure - 用于管理数百万订阅者(即客户)的 Webhook 架构
- c# - C# FileVersionInfo.GetVersionInfo (FilePath) 行为异常
- swift - 为什么 Swift 编译器不能推断类型?
- android - Google Play 管理中心:如何将 Android 应用从 Alpha 升级到 Beta
- routing - IE11 的 Angular6 路由问题