C# asp.net文字控件bgcolor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1269975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
asp.net literal control bgcolor
提问by Nagu
How can I change the bgcolor
and font
of my asp:Literal
control?
如何更改我的控件的bgcolor
和?font
asp:Literal
Can you give me an example?
你能给我一个例子吗?
回答by Noon Silk
Literal control means it doesn't output any surrounding tags. So include whatever tags you want in the .Text property of it and mark them appropriately.
文字控制意味着它不输出任何周围的标签。因此,在它的 .Text 属性中包含您想要的任何标签并适当地标记它们。
E.g.
例如
ltlFoo.Text = "<font style='background : orange;'>hello</font>";
回答by attack
Silky is totally right, but please, please for my sanity, use CSS instead of inline styles:
Silky 是完全正确的,但是为了我的理智,请使用 CSS 而不是内联样式:
<style type="text/css">
.beautiful
{
font-family: Georgia, serif;
color: #369;
}
</style>
<asp:Literal ID="myLitControl" runat="server" Text="<div class='beautiful'>Some Beautiful Text</div>" />
回答by Kelsey
Literal controls only output exactly what you put in them, nothing else.
文字控件只输出您输入的内容,没有其他内容。
Label controls do the same but wrap them in a span which you could do apply a style to. Change your Literal to a Label and you should be good to go.
标签控件执行相同的操作,但将它们包装在一个跨度中,您可以对其应用样式。将您的文字更改为标签,您应该很高兴。
回答by Saahithyan Vigneswaran
In simple asp:Literal
is a style less control, so enclose this with another element like div or span and give style to this element.
simpleasp:Literal
是一个样式较少的控件,因此将其与另一个元素(如 div 或 span)一起使用,并为该元素赋予样式。
回答by Michael Espinoza Betanco
I have done this
我已经这样做了
<div style="color:rgba(255, 255, 255, 1)">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False" ></asp:Literal>
you can create a CSS class then put it inside a DIV
你可以创建一个 CSS 类然后把它放在一个 DIV 中