c#中asp.net标签前加空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17876016/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:43:06  来源:igfitidea点击:

Add space before asp.net label in c#

c#asp.netlabel

提问by Madhavan NR

I want to add some space before asp.net Label.I can't do this in .aspx ,I want this to be done in c#.How can I add space?? please help me.my label is placed like this:

我想在 asp.net 标签之前添加一些空间。我不能在 .aspx 中执行此操作,我希望在 c# 中完成此操作。如何添加空间?请帮帮我。我的标签是这样放置的:

                    Label Test

I want this to come to centre

我想让这个居中

                                       Label Test

采纳答案by arturogarrido

To add spaces to your label text from c#, you can pre-append many HTML non-breaking spaces by using  Example:

要从 c# 向标签文本添加空格,您可以使用 示例预先附加许多 HTML 不间断空格:

Label1.Text = "     " + Label1.Text;

回答by Abhitalks

Apply the style text-align: centerto its parent.

将样式应用text-align: center到其父项。

You can have a parent like:

你可以有这样的父母:

<div style="width: 100%; text-align:center">
<label>text</label>
</div>

Alternatively, you can give a width and block to the label itself:

或者,您可以为标签本身提供宽度和块:

<label style="display:inline-block; width:100%; text-align:center">text</label>

For code-behind you can add it to attributes:

对于代码隐藏,您可以将其添加到属性中:

YourLabel.Attributes.CssStyle.Add("text-align", "center")

回答by Aditya Singh

Try adding the Css Style or Css Class:-

尝试添加 Css 样式或 Css 类:-

lblTest.Attributes.CssStyle.Add("margin-left", "<value>");

lblTest.Attributes.CssStyle.Add("margin-left", "<value>");

or

或者

lblTest.Attributes.Add("class","<className>");and specify the css style in the specified class.

lblTest.Attributes.Add("class","<className>");并在指定的类中指定css样式。

回答by Arshad

you can do it by adding a span from .cs file like :

您可以通过从 .cs 文件中添加一个跨度来实现,例如:

protected void Button1_Click(object sender, EventArgs e)
{
 Label1.Text ="<span style=\"margin: 0px 0px 0px 180px;\"></span>" + "your text";
}