css - 样式表代码不会反映在剃须刀页面上
问题描述
我正在开发我的第一个 .net 核心 Web 应用程序。我正在尝试将我的公司徽标放在 _layout.cshtml 页面中,但 _layout 页面似乎无法识别样式表 site.css。下面是我的 _layout.cshtml 页面代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - VitalRecords</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="headerDiv">
<div class="headerTopBanner"></div>
<div class="headerLogo">
<div class="logo"></div>
</div>
<h1 class="display-4">Welcome</h1>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
© 2020 - test - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)
</body>
</html>
我的 site.css 定义了以下内容:
.headerDiv {
background-color: white;
}
.headerTopBanner {
background-color: $header-top-banner-color;
height: 5px;
width: 100%;
}
.headerLogo {
padding: 5px;
padding-left: 10px;
vertical-align: middle;
}
.logo {
background: url(../../images/LogoWithDesc) 0 0;
min-height: 70px;
vertical-align: middle;
}
$header-top-banner-color: #FD810A;
输出的屏幕截图如下所示:
我在 Index.cshtml 中有类似的代码:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="headerDiv">
<div class="headerTopBanner"></div>
<div class="headerLogo">
<div class="logo"></div>
</div>
<h1 class="display-4">Welcome</h1>
</div>
这就是为什么欢迎在我的页面上出现两次,但徽标和其他一些颜色没有出现。似乎 site.css 根本无法识别。
任何帮助将不胜感激,
解决方案
尝试css link
像这样导入你的
<link href="@Url.Content("~/css/site.css")" rel="stylesheet" type="text/css" />
推荐阅读
- java - Cucumber 4.7.2 将表转换为行到对象
- java - 如何使用 Spring Boot 2 在 Spring Data JPA 中处理自引用?
- c# - ASP Classic:修改 cookie 字符串后 cookie 键不可读
- javascript - 尝试将版本添加到 javascript 导入时出现 SyntaxError
- ios - Xamarin.Forms 中的 Newtonsoft.Json 动态异常 - 仅在 IOS/Device/Release 中
- r - ggplot:将网格线与 geom_tile 的末端对齐
- elasticsearch - 使用 Elasticsearch 和 .NET 进行脚本更新期间的冲突
- linux - Linux 哈希值
- swift - 在 Swift 中映射对象数组的问题
- c# - 下载后图片不显示在图库中