【问题标题】:How can I add the css to my project asp.net mvc? [closed]如何将 css 添加到我的项目 asp.net mvc 中? [关闭]
【发布时间】:2015-10-31 00:29:07
【问题描述】:

我正在制作一个项目 Asp.net mvc,我找到了一个免费的 css 模板,我试图添加到我的项目中,但我没有获得成功的结果。

在“内容”文件夹中,我有 css 文件。

在“查看/共享”文件夹中,我有一个 _Layout.cshtml,头部有这段代码 <link href="@Url.Content("~/Content/css/Site.css")" rel="stylesheet" type="text/css">
但它对我不起作用。

【问题讨论】:

  • 您应该在此处添加其他信息。请张贴_Layout.cshtml的负责人。
  • @ViewBag.Title @System.Web.Optimization.Styles。渲染("~/Content") @RenderBody()

    版权所有 W3schools 2012。保留所有权利。

标签: html css asp.net asp.net-mvc visual-studio-2013


【解决方案1】:

您可以将链接放在位于共享文件夹中的 Layout.cshtml 文件中。像这样,或者你可以看看捆绑。 http://www.asp.net/mvc/overview/performance/bundling-and-minification

<head>
   <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
   <script src="~/Scripts/modernizr-2.6.2.js"></script>
   <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
</head>

【讨论】:

  • 我这样做了,但它不起作用
  • 你能把_Layout.cshtml文件贴出来吗?
【解决方案2】:

这是您可以在 _Layout.cshtml 视图中添加新 css 文件的方法。

<head>
...
    <link href="@Url.Content("~/Content/CSSFileName.css")" rel="stylesheet">
</head>

您可能需要查看您使用的 .css 文件是否与您现有项目中的类匹配。

【讨论】:

  • 我是这样写的,但它不起作用
  • 能否贴出你要使用的相关.css文件?
  • &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; &lt;link href="@Url.Content("~/Content/css/Site.css")" rel="stylesheet" type="text/css"&gt; &lt;link href="~/Content/css/Site.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt;
【解决方案3】:

这是我的 _Layout.cshtml 和 css

body
{
font: "Trebuchet MS", Verdana, sans-serif;
background-color: red;
color: #696969;
}
h1
{
border-bottom: 3px solid #cc9900;
font: Georgia, serif;
color: #996600;
}
#main
{
padding: 20px;
background-color: #ffffff;
border-radius: 0 4px 4px 4px;
}
a
{
color: #034af3; 
}
/* Menu Styles ------------------------------*/ 
ul#menu
{
padding: 0px;
position: relative;
margin: 0;
}
ul#menu li
{
display: inline;
}
ul#menu li a 
{
background-color: #e8eef4;
padding: 10px 20px;
text-decoration: none;
line-height: 2.8em;
/*CSS3 properties*/
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover
{
background-color: #ffffff;
} 
/* Forms Styles ------------------------------*/ 
fieldset
{
padding-left: 12px;
} 
fieldset label
{
display: block;
padding: 4px;
}
input[type="text"], input[type="password"]
{
width: 300px;
}
input[type="submit"]
{
padding: 4px;
}
/* Data Styles ------------------------------*/ 
table.data
{
background-color:#ffffff;
border:1px solid #c3c3c3;
border-collapse:collapse;
width:100%;
}
table.data th
{
background-color:#e8eef4;
border:1px solid #c3c3c3;
padding:3px;
}
table.data td 
{
border:1px solid #c3c3c3;
padding:3px;
}
        
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/css/Site.css")" rel="stylesheet" type="text/css">

    <link href="~/Content/css/Site.css" rel="stylesheet" type="text/css" />  
  
</head>
<body>
    <ul id="menu">
        <li>@Html.ActionLink("Home", "Index", "Home")</li>
        <li>@Html.ActionLink("Movies", "Index", "Movies")</li>
        <li>@Html.ActionLink("About", "About", "Home")</li>
    </ul>
    <section id="main">
        @RenderBody()
        <p>Copyright W3schools 2012. All Rights Reserved.</p>
    </section>

   
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 2014-08-23
    • 1970-01-01
    相关资源
    最近更新 更多