2013-09-30 54 views
0

當我想將我的一種CSS樣式應用於asp標籤時,我有一個特殊的結果。樣式實際上只有部分效果,例如像background-color這樣的屬性,顏色正在起作用,而寬度和高度不起作用。我不明白爲什麼。無法將CSS樣式應用於一個asp標籤

ASP

<div id="wrap"> 
<div id="left" class="Tablestyle"> 
<asp:Label ID="Label1" runat="server" Text="Entry Number: " class="Tablestyle"></asp:Label> 
<br /><div class="separator">&nbsp;</div> 
<asp:Label ID="Label3" runat="server" Text="ID Number: " class="Tablestyle"></asp:Label> 
<br /><div class="separator">&nbsp;</div> 
<asp:Label ID="Label2" runat="server" Text="Type: " class="Tablestyle"></asp:Label> 

</div> 
<div id="Mid">&nbsp</div> 
<div id="right"> 
<asp:Label ID="IdBox" runat="server" class="TableStyleInfo"></asp:Label> 
<br /><div class="separator">&nbsp;</div> 
<asp:Label ID="IdNumBox" runat="server" class="TableStyleInfo"></asp:Label> 
<br /><div class="separator">&nbsp;</div> 
<asp:Label ID="TypeBox" runat="server" class="TableStyleInfo"></asp:Label> 
</div> 
</div> 

CSS

#wrap 
{ 
width:555px; 
margin:auto; 
text-align:center; 
} 

#Mid 
{ 
width:5px; 
height:330px; 
float:left; 
background-color:White; 
} 

#right 
{ 
width:400px; 
float:left; 
text-align:left; 
background-color:Yellow; 
} 

#left 
{ 
width:150px; 
float:left; 
text-align:right; 
background-color:Green; 
} 

.separator 
{ 
height:4px; 
line-height:4px; 
background-color:White; 
} 

.Tablestyle 
{ 
width:150px; 
height:20px; 
text-align:right; 
color:white; 
font-weight:bold; 
background-color:#507CD1; 
} 

.TableStyleInfo 
{ 
width:400px; 
height:20px; 
text-align:left; 
color:Black; 
background-color:#EFF3FB; 
} 

我試着也在發生變化classCssClass但什麼也沒發生一樣。

如果有人能指出我的錯誤或給我提示,爲什麼我不能應用寬度和高度屬性,我將不勝感激。

+0

我有一些改進。我將float:left添加到適用於asp標籤的類TableStyle和TableStyleInfo中。現在itgets正確的寬度,但'separator' divs不可見=( – meks

回答

1

<asp:Label>轉換爲html <span>元素,該元素是內聯元素,並且沒有寬度或高度。您可以通過將它們更改爲css中的塊級元素來執行此操作:

.Tablestyle { 
    display: block; // add this 
    width: 150px; 
    height: 20px; 
    text-align: right; 
    color: white; 
    font-weight: bold; 
    background-color: #507CD1; 
} 

.TableStyleInfo { 
    display: block; // add this 
    width: 400px; 
    height: 20px; 
    text-align: left; 
    color: Black; 
    background-color: #EFF3FB; 
} 
+0

時刻,讓我試試 – meks

+0

是的,它的工作,非常感謝! – meks