MasterPage And ContentPage Body Css Problem?
-
24-01-2021 - |
Question
I have a Masterpage and I have a content page from this masterpage.. I must use different css for body tag for only this contentpage? How can ı do this?
this is my masterpage's css
body, div, ul, ol, li, p, h1, h2, h3, span, pre, a, img, blockquote, table, tbody, tfoot, thead, tr, th, td, pre, code {
margin:0px; padding:0px; border:0 none; outline:0; vertical-align:baseline;}
I dont want this css code for my contentpage.. How can ı do this?
Solution
You could create a control in the Master page with the CSS included. Such as:
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
<title>Master page title</title>
</head>
<asp:contentplaceholder id="CSS" runat="server">
<style type="text/css">
body, div, ul, ol, li, p, h1, h2, h3, span, pre, a, img, blockquote, table, tbody, tfoot, thead, tr, th, td, pre, code {
margin:0px; padding:0px; border:0 none; outline:0; vertical-align:baseline;}
</style>
<body>
</body>
</html>
You could then place a Content control on the client page overriding the master and just omit the content control on the rest of the pages (they will inherit the default).
I would recommend using a separate CSS file instead of embedding it directly, but you can accomplish that easily as well.
OTHER TIPS
As far as im aware the only way you can do this would be to create a 2nd master page for this particular content page.
I would suggest removing the styles from the master page & include them in each content page as needed, your master page should apply to every page the same, without causing any issues
Sorry, but I'll suggest you include this css in the page you need it, not in the masterpage, since you don't want it in every pages... I guess this is not the answer you expected, but that's how CSS is work :S