Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where and how do i call different CSS for different browsers in my MVC website?

I am developing a website and have noticed that it does not preform correctly on all the browsers.

I Would like to create a different CSS style sheet for each browser, mainly IE.

My problem comes in on how to call the different style sheets with the different browsers.

I also cant find where the main site.css is called in my MVC website, if someone could show me where the site.css is called in a MVC website that would be great.

So where and how do i call different style sheets for different browsers in a MVC website?

like image 307
Pomster Avatar asked Nov 26 '12 11:11

Pomster


People also ask

Where does CSS go in MVC?

The style sheet for the application is called Site. css. It is located in the Content folder.

Does browser understand CSS?

The browser parses the HTML and creates a DOM from it. Next, it parses the CSS. Since the only rule available in the CSS has a span selector, the browser sorts the CSS very quickly!


1 Answers

Using a browser specific stylesheet is no different in ASP .NET MVC. You put the if statement and point to the stylesheet. See more here. You can put your stylesheet statements in the _Layout.cshtml file in the Views\Shared folder

In ASP .NET MVC, the stylesheet is in the Content folder.

ASP .NET MVC 4 uses Minification and Bundling. Look inside the App_Start folder, you will see a BundleConfig.cs file, and inside, you will see the bundles that contain the css and javascript. In the _layout.cshtl file, you will see code that references these bundles ,which is something like @Styles.Render("~/Content/css").

"So where and how do i call different style sheets for different browsers in a MVC website?"

In the Layout file which has your <head> tags. like this:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")
        <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="iespecific.css" />
        <![endif]-->

    </head>
    ....
like image 164
robasta Avatar answered Oct 22 '22 11:10

robasta