html - 无法将 CSS 样式应用于 asp 标签

标签 html asp.net css

当我想将我的一种 CSS 样式应用到 asp 标签时,我得到了一个奇怪的结果。样式实际上只有部分效果,例如 background-color 和 color 等属性正在生效,而 width 和 height 则没有。我不明白为什么。

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;
}

我也尝试将 class 更改为 CssClass 但没有发生任何相同的事情。

如果有人能指出我的错误或提示我为什么不能应用宽度和高度属性,我将不胜感激。

最佳答案

<asp:Label>转换为 html <span>元素,它是一个内联元素,没有宽度或高度。您可以通过将它们更改为 css 中的 block 级元素来强制执行此操作:

.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;
}

关于html - 无法将 CSS 样式应用于 asp 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085885/

相关文章:

javascript - on scroll,隐藏滚动条和 overflow hidden 的同时触发事件

javascript - asp.net 未在复选框中显示选中和未选中状态

javascript - 鼠标悬停时重新绘制 Canvas

javascript - 隐藏当前未被选中的菜单

html - IE11 上的 Flexbox : image stretched for no reason?

javascript - HTML5 Canvas 中的超高分辨率图像

javascript - 仅在移动设备上全屏覆盖导航

html - 为什么绝对定位的页脚消失了

c# - 将 SCORM 类(class)导入我的 LMS

asp.net - 如何强制浏览器不存储HTML表单字段数据?