C# 向asp.net标签添加样式
我想给asp.net标签添加样式,但它不起作用C# 向asp.net标签添加样式,c#,asp.net,webforms,C#,Asp.net,Webforms,我想给asp.net标签添加样式,但它不起作用 ASP.NET Mark up <asp:Label runat="server" ID="lblCommentText"/> Generated from the backend: Html mark up <span id="ctl02_ctl36_CommentText">Only the leave the comment please</span> .........................
ASP.NET Mark up
<asp:Label runat="server" ID="lblCommentText"/>
Generated from the backend: Html mark up
<span id="ctl02_ctl36_CommentText">Only the leave the comment please</span>
............................................
我试过使用
lblCommentText.Attributes.csssstyle.Add(“float”,“right”)代码>到后端
document.getElementById(“”).Style.display=(“float”,“right”)代码>
它们都不起作用,有人能帮我吗?标签呈现为跨距,跨距基本上是内联元素。您需要将其设置为块或内联块,以便使浮动和宽度生效
.yourclass {
display: inline-block;
float: right;
width: 70%;
}
然后简单地使用cssclass
:
<asp:Label runat="server" ID="lblCommentText" CssClass="yourclass" />
如果要从代码隐藏中添加,请使用以下命令:
lblCommentText .Attributes.CssStyle.Add("float", "right");
lblCommentText.Attributes.CssStyle.Add("width", "70%");
如果要从aspx页面添加,请创建一个css类,如:
.testClass{float: right;width: 70%;}
这样分配:
asp:Label runat="server" ID="lblCommentText" runat="server" Text="test data" CssClass="testClass"
内联:
<asp:Label runat="server" ID="lblCommentText" style="float:right" />
使用类:
<style>
.styleclass{
float: left;
}
</style>
<asp:Label runat="server" ID="lblCommentText" CssClass="styleclass" />
.styleclass{
浮动:左;
}
使用身份证
<style>
#ctl02_ctl36_CommentText {
float: left;
}
</style>
<asp:Label runat="server" ID="lblCommentText" />
#ctl02\u ctl36\u注释文本{
浮动:左;
}
显示:内联块
将@abhitalks在.class
中所说的内容耦合起来,并使用标签上的CssClass
属性应用该类。
<style>
#ctl02_ctl36_CommentText {
float: left;
}
</style>
<asp:Label runat="server" ID="lblCommentText" />