MVC .NET CSS 未被视图拾取
我正在 MVC2 站点上工作,并且在让我的视图上的对象继承 css 类时遇到问题。
这是我的辅助对象和 CSS,保存在 Site.css 中,该 CSS 链接在母版页中。
如果我将 CSS 放在母版页的标签中,这也可以正常工作。
<%= Html.ListBox("ExpenseItems", (System.Web.Mvc.SelectList)ViewData["ExpenseDefinitions"], new { @class = "optionlist" })%>
.optionlist
{
width:100px;
height:100px;
}
Browser HTML:
..
<link href="../Content/Site.css" rel="stylesheet" type="text/css" />
..
<select class="optionlist" id="ExpenseItems" multiple="multiple" name="ExpenseItems">
<option value="1">Test</option>
</select>
I am working on a MVC2 site and am having issues getting my objects on my views to inherit the css classes.
Here is my helper object and CSS that is saved in the Site.css which is linked in the master page.
This also works fine if I put the CSS in a tag on the masterpage.
<%= Html.ListBox("ExpenseItems", (System.Web.Mvc.SelectList)ViewData["ExpenseDefinitions"], new { @class = "optionlist" })%>
.optionlist
{
width:100px;
height:100px;
}
Browser HTML:
..
<link href="../Content/Site.css" rel="stylesheet" type="text/css" />
..
<select class="optionlist" id="ExpenseItems" multiple="multiple" name="ExpenseItems">
<option value="1">Test</option>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了...无法将样式应用到列表。
出于某种原因,您需要将其应用于 div,然后应用于 CSS 中的控件。
例子:
Figured it out... Can't apply the style to the list.
Some reason, you need to apply it to a div then apply to the control in CSS.
example:
当您以这种方式链接 css 文件时,并且如果您正在浏览具有这样的 url 的页面
http://yoursite.com/MyPage/Content/Article
当然,css 文件不会被发现,因为它是这样走的。我的建议是在你的css链接中添加一个基本url
不要将
"
放在链接标签的href中when you link your css file that way, and if you are browing in in a page with a url like this
http://yoursite.com/MyPage/Content/Article
of course the css file will not be found since it goes this way.My suggestion is add a base url to your css link
Don't put
"
in href of the link tag