2010-05-05 62 views
0

學習如何在asp.net中做母版頁。試圖弄清楚我的樣式表如何與尊重主頁和內容頁的交互。我可以得到HTML標籤,比如body和樣式表來做出反應。但是,當我調用標籤的ID屬性時,不會發生樣式。就交互而言,我在這裏錯過了什麼? BTW我使用VS2008asp.net母版頁/內容頁面與樣式表的交互

CSS樣本:

body 
{ 
height:1200px; 
width:920px; 
border-style:solid; 
border-color:blue; 
padding:10px 10px 10px 10px; 
} 

#toptext1 
{ 
position:relative; 
top:-225px; 
right:-500px; 
font-size:22px; 
font-weight:bold; 
} 

從母版頁:

<body> 
    <form id="form1" runat="server"> 
     <asp:image id="cookNookLogo" ImageUrl="images/Logo.gif" runat="server" 
     AlternateText="CookNook" Width="449px"></asp:image> 
    <p> 
    <asp:Label ID="toptext1" runat="server" Text="Quality Recipes, Hints and Supplies"></asp:Label> 

</p> 

從內容頁:

<%@ Page Language="C#" MasterPageFile="~/CNMasterPage.master" AutoEventWireup="true"  CodeFile="Home.aspx.cs" Inherits="Home" Title="Untitled Page" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 

<link href="App_Themes/cn/cn.css" rel="stylesheet" type="text/css" /> 

</asp:Content> 

當我這樣做不一個母版頁,它的工作,我在哪裏出錯的屬性?

+0

您是使用ASP.NET還是經典ASP? – 2010-05-05 19:55:41

回答

3

你可能有這樣的事情,而不是

CSS

.toptext1 
{ 
position:relative; 
top:-225px; 
right:-500px; 
font-size:22px; 
font-weight:bold; 
} 

ASPX

<asp:Label ID="toptext1" runat="server" CssClass="toptext1" Text="Quality 
Recipes, Hints and Supplies"></asp:Label>

肖恩維埃拉說。您分配給網頁控件的ID與發送給瀏覽器的ID不同。

這裏有一個很好的教程,解釋.NET如何管理Web控件的ID。

http://www.asp.net/LEARN/master-pages/tutorial-05-vb.aspx

+0

您分配給網頁控件的標識與發送給瀏覽器的標識不同。 ....我學習一種新語言時忽視的東西。 謝謝! – Matt 2010-05-05 20:06:49

2

如果你看一下你的頁面生成的源代碼,你會看到.NET具有更換你的ID有一個更爲詳細的ID,指定容器,它是在一節。

看你的代碼中,ID可能是這樣的:c100_toptext1(儘管它依賴於.NET的版本,您正在使用)

相關問題