0

I am building an application in .net core 2.0 Razor pages and cannot get the site.css file to render what I want it to. I am string to customize the _layout.cshtml file by changing the nav bar. When I run the project the CSS does not apply going so far as to when I inspect the page the css that is being rendered is not even the file that I have changed.

The CSS code is:

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;
    }
}

and the _layout.cshtml is:

<!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>

When I run the solution I get page that looks like: Site after build with the site.css file that is being rendered

How do I get the CSS to render properly?

0

1 Answer 1

1

You put the site.css in the environment exclude. Comment that out and see if it works.

Sign up to request clarification or add additional context in comments.

5 Comments

That worked. Can you explain why that would be as I haven't changed any of the boilerplate code except for what is in the <body> tags
I believe it's because you're testing it in a "development environment" while at the same time telling the program to exclude that .css file for development environments
If that's how the project comes out of the box, to me, that seems a bit of a silly thing to do.
I'm pretty sure the exlude comes with a site.min.css out of the box and you accidently deleted the .min.
@Marco I haven't deleted the site.min.css as i can see it is nested in the project explorer. The issue I had with that was that I didn't want to update the .min and if the .min gets compiled then that wasn't working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.