1

我试图阻止文本换行。如何将其添加nowrap到以下内容并保持一切正常?

html.Append("<ins style=\"background:#e6ffe6;\">").Append(text) 
                        .Append("</ins>");

需要添加如下内容:

// style='white-space:nowrap; display:inline;'

当我添加它时,它会破坏我的样式。我想我添加错了?

html.Append("<ins style='white-space:nowrap; display:inline;',style=\"background:#e6ffe6;\">").Append(text) 
                            .Append("</ins>");
4

3 回答 3

2

您拥有该style属性两次,请尝试以下操作:

html.Append("<ins style=\"white-space:nowrap; display:inline; background:#e6ffe6;\">")
    .Append(text) 
    .Append("</ins>");

但是,IMO 样式最好保留在 CSS 文件中。您可以设置一个适当的类(或类):

html.Append("<ins class=\"aClass\">")
    .Append(text) 
    .Append("</ins>");

然后在你的 CSS 文件中:

.aClass {
  white-space:nowrap; 
  display:inline; 
  background:#e6ffe6;
}
于 2012-06-26T11:30:06.613 回答
0

你做错了,style=Style属性在 html 元素中只能出现一次。您必须一次编写样式属性:

html.Append("<ins style='white-space:nowrap; display:inline;background:#e6ffe6;'>).Append(text) 
                        .Append("</ins>");
于 2012-06-26T11:30:50.133 回答
0

为什么不将所有三个样式属性组合在一个样式标签中?

html.Append("<ins style=\"background:#e6ffe6;white-space:nowrap; display:inline;\">").Append(text).Append("</ins>");
于 2012-06-26T11:32:04.413 回答