I tried using
<link href="@Url.Content("~/Content/Extras.css")"
rel="stylesheet" type="text/css" />
but got a warning
Validation (XHTML 1.0 Transitional): Element 'link' cannot be
nested within element 'link'.
So I tried
<style></style>
and got a very similar warning
"Validation (XHTML 1.0 Transitional): Element 'style' cannot be
nested within element 'style'."
How can I conform to this validation?
As Alirizaadiyahsi linked in a comment (although it has since been removed) the cause of this warning is that <link>
and <style>
tags may only go in the head of the document.
This is an issue for me because I want to have custom styles for certain areas in my asp.net mvc 3 site. To solve the problem, I did this:
<script type="text/javascript">
var x = document.createElement("link");
x.setAttribute("href",'@(Url.Content("~/Content/Extras.css"))');
x.setAttribute("rel", "stylesheet");
x.setAttribute("type", "text/css");
$('head')[0].appendChild(x);
</script>