Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a .css to a .cshtml

Tags:

html

css

razor

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; 
}
like image 577
Smoore Avatar asked Oct 30 '12 17:10

Smoore


People also ask

How do I add a style sheet to a Web page?

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.

Where do I put CSS code in asp net?

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.


2 Answers

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; 
}
like image 197
Fenton Avatar answered Sep 16 '22 19:09

Fenton


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>
like image 30
ScriptKiddieOnAComputer Avatar answered Sep 16 '22 19:09

ScriptKiddieOnAComputer