I'm a complete html/css novice and I am trying to get a .cshtml file to use some basic CSS I wrote. What code do I need to put in my .cshtml to get it to use the CSS file?
Edit: This is the code in my .css file. It is intended to style my div
with the id of "comment_box1", but even after following the answer, it's not working. Any idea what's wrong?
.comment_box1 {
background-color: #C8E0E8;
width: 830px;
height: 180px;
}
To add an external stylesheet to a web page, use the <link> tag, providing the URL of the style sheet in the href attribute, as well as rel="stylesheet" . For the following example, I've taken the styles from the above (embedded) example, moved them to an external style sheet, then linked to that file.
Drag and drop css below header file->then go to downloaded css template and open that template -> right click on the template and click the option "view page source" -> copy the template body code-> open the master page -> paste the template body code within the body of master page.
Here is the basic option - you add a style tag to the <head>
of your document...
<link rel="stylesheet" href="app.css" type="text/css" />
If you are using bundles, you place the bundle there instead:
@Styles.Render("~/Content/css")
And finally, if you are using a master layout, that's the best place to put this as it will then apply to all your pages.
Update
If you are targeting an id, you use #
, rather than the dot, which is for a class.
#comment_box1
{
background-color: #C8E0E8;
width: 830px;
height: 180px;
}
You could also make the use of while using CSS in .cshtml files. In this case, paste the following code directly into your .cshtml file:
<style>
#comment_box1
{
background-color: #C8E0E8;
width: 830px;
height: 180px;
}
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With