Reputation: 5905
While implementing an html template in MVC web site which was designed by some agency I m facing something a little challenging. The templates was containing different html pages which have different css classes applied in body tag. I have converted common parts of all pages into a Layout/Master Page
so <body>
tag is also in Layout/Master Page
.
Question is how I should render Layout (HTML) with different css classes applied to tag ?
Upvotes: 2
Views: 2331
Reputation: 91
Remove the body tag from layout. Put it in each Main View Template and set the body class there.
Just make sure to put all the partials (like the header, top nav, left nav, footer) inside the body tags. The caveat is that you will have to put the body tag in each Main View, but it will allow you to apply any class you want to the <body>
tag.
Other than that, you can use JavaScript to add a class to the body. Use the JavaScript in each view that needs to change the body class:
$("body").addClass("yourClassName");
Add an id attribute to the <body>
tag: <body id="body"> ... </body>
document.getElementById("body").className = "yourClassName";
Upvotes: 2
Reputation: 39258
Just load specific css files in the various child views. You can override the body style in each case.
Upvotes: 2