CSS: Possible to define styles mid way through an html document?
In ASP.NET MVC, there are these snippets of html called view templates which appear when their matching data appears on the screen. For example, if you have a customer order and it has a vendor address, the vendor address view template shows up populated with开发者_StackOverflow中文版 data.
Unfortunately, these don't have access to "MasterPages" nor are aware of their CSS surroundings.
Instead of loading these up with style tags, is there any way to create partial CSS files that could work for that particular html snippet, a sort of in-line CSS style section?
It would be really nice to plop this down just before we render the partial view:
<style type="text/css">
input { margin: .2em .2em;
overflow: hidden;
width: 18.8em;
height: 1.6em;
border: 1px solid black;}
</style>
to have the 15 or so input fields in that particular Html snippet be formatted the same. These are swapped out, so the positions of the input fields change. This may also imply a CSS reset on each partial view.
I thing that an idea would be to include an additional content section in Head
of the master page
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="CssContent" runat="server" />
</head>
In doing so, you can then inject the specific styles for each view.
Edit: After posting I think the above is not what you are referring to. What you may consider is rolling your own ViewUserControl
similar to Script & CSS Registration Helper in ASP.NET MVC??
Why not have a css file that is referenced in the partial views or am I mising the point of the question?
精彩评论