Search code examples
asp.nethtmlcssmaster-pagescontent-pages

MasterPage And ContentPage Body Css Problem?


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.