using Css and master page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghulvarma
    New Member
    • Oct 2007
    • 90

    using Css and master page

    I have created a master page
    <%@ Master Language="C#" AutoEventWireup ="true" CodeFile="Maste rPage.master.cs " Inherits="Maste rPage" %>
    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <h1 style="color:blue">This is From Master page</h1>
    <table width="80%">
    <tr valign="top">
    <td style="width:200px">
    to:do
    </td>
    <td>
    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
    </asp:contentplaceholder>
    </td>
    </tr>
    </table>
     
    </div>
    </form>
    </body>
    </html>
    then i used that master page in my .aspx pages as
    Code:
     
    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="Default.aspx.cs" Inherits="_Default" %>
      
     
    <asp:Content ID="content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
     
    <asp:Label runat="server" ID="lbl1" Text="User Name" style="position:absolute; left: 265px; top: 130px;"></asp:Label>
    <asp:TextBox runat="server" ID="txt1" style="position:absolute; left: 385px; top: 130px;"></asp:TextBox>
    <br />
    <asp:Label runat="server" ID="Lbl2" Text="password" style="position:absolute; left: 265px; top: 160px;"></asp:Label>
    <asp:TextBox runat="server" ID="txt2" style="position:absolute; left: 385px; top: 160px;"></asp:TextBox>
    </asp:Content>
    all these work fine but if I need to add a style sheet to my aspx page I am not able to do so because I am not able to get the tag of <link> which is used to link a css to our page how has it to be done?
    any clues????

    raghul
    Last edited by DrBunchman; Jul 5 '08, 06:19 PM. Reason: Added code tags - Please use the # button
  • deepant
    New Member
    • May 2008
    • 5

    #2
    Hi,

    you must link your css file in teh master page itself, so that when you inherit the master page when you creating a page the stylesheet applied with the master page will be applied to your created pages also

    you can attach the css file in the master pages using the <link> tag

    you can use this tag in the <head> section

    <link href="your stylesheet name with location" rel="stylesheet " type="text/css" />

    you should move all your styles to a seperate stylesheet file(.css) so that it is easy to change if ther is any changes in the style

    if you change the style in the stylesheet it will be applied to all your pages

    Thanks,
    Hema

    Comment

    Working...