.net核心网站未呈现CSS

时间:2018-07-18 13:46:44

标签: c# html css .net razor

我正在.net core 2.0 Razor页面中构建应用程序,但无法获取site.css文件来呈现我想要的文件。我是通过更改导航栏来自定义_layout.cshtml文件的字符串。当我运行项目时,CSS不适用于检查页面时呈现的CSS甚至不是我已更改的文件。

CSS代码为:

body {
padding: 0;
margin: 0;
border: 0;
}

.navigation {
    background-color: blue;
    color: white;
    float: left;
    width: 20vw;
    height: 100vh;
}

/* Wrapping element */
/* Set some basic padding to keep content from hitting the edges */
.body-content {
    padding-left: 15px;
    padding-right: 15px;
}

div.table {
    display: table;
}

div.table > div.thead {
    display: table-header-group;
}

div.table > div.tbody {
    display: table-row-group;
}

div.table > div.thead > div.table-row,
div.table > div.tbody > div.table-row {
    display: table-row;
}

div.table > div.thead > div.table-row > div.table-heading {
    display: table-cell;
    font-weight: bold;
}

div.table > div.tbody > div.table-row > div.table-cell {
    display: table-cell;
}

/* Hide/rearrange for smaller screens */
@media screen and (max-width: 767px) {
    /* Hide captions */
    .carousel-caption {
        display: none;
    }
}

和_layout.cshtml是:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - AdeptFrontEnd</title>

    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" runat="server"/>
        <link rel="stylesheet" href="~/css/site.css" runat="server" type="text/css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
    </environment>
</head>
<body>
    <nav class="nav flex-column navigation">
        <ul class="nav flex-column">
            <li><a asp-page="/Network/Index" class="navbar-brand">Adept</a></li>
            <li><a asp-page="/Network/Index">Network</a></li>
            <li><a asp-page="/Network/Index">Network</a></li>
        </ul>
    </nav>
    <div class="container body-content">
        @RenderBody()
    </div>

    <environment include="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment exclude="Development">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
        </script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>

    @RenderSection("Scripts", required: false)
</body>
</html>

运行解决方案时,我得到的页面如下: Site after build with the site.css file that is being rendered

如何使CSS正确呈现?

1 个答案:

答案 0 :(得分:1)

您将site.css放在排除环境中。注释掉它,看看是否可行。