从代码添加样式属性的HTML标签后面使用C#
问题描述:
大家好,
我要添加使用C#我的HTML标签的样式属性。请找到下面的代码。
StringBuilder mailBody = new StringBuilder();
mailBody.AppendFormat("<html>");
mailBody.AppendFormat("<p>Please note:</p>");
mailBody.AppendFormat("<p> " + data + " folder no longer exists on the network. Please review at your earliest convenience. </p>");
mailBody.AppendFormat("<br/>");
mailBody.AppendFormat("<p>Thank you</p>");
mailBody.AppendFormat("<p>Development Team</p>");
mailBody.AppendFormat("</html>");
emailBody = mailBody.ToString();
和输出是:
在图像字体样式显示的文本是“时代新罗马”。我怎么能改变它以显示任何其他字体类型。我怎么能在上面的HTML标签中添加。
在此先感谢。
答
<p><span style="font-family:Verdana">Please note:</span></p>
答
样式添加到标签,就像这样:
<p style="font-family:courier">Please note:</p>
检查更多的信息在这里:http://w3schools.com/html/html_styles.asp
答
<p style="font-family:arial black">Please note:</p>
请通过这个链接了解更多info
答
一个更简单的方法是将其放在CSS
BODY P
{
}
然后你不会需要把它变成所有P标签
或者,如果你想只有它适用于部分 你应该在一个div围绕这一点,然后
.<DivClassName> P
{
}
答
我会做到这一点,那么你正在采取的Advanta CSS的GE:
var mailBody = new StringBuilder();
// put in the font(s) you'd like to use. If font 1 isn't installed,
// it will move on to the next font in line, and so forth.
var font = "Arial, Calibri, 'Trebuchet MS', sans-serif";
// the color of the text. If you'd like to use more colors, take
// advantage of CSS classes.
var color = "red";
mailBody.Append("<html><head>");
mailBody.Append("<style type=\"text/css\">");
mailBody.AppendFormat("body { font-family: {0}; color: {1}; }",
font, color);
mailBody.Append("</style>");
mailBody.Append("<p>Please note:</p>");
mailBody.AppendFormat("<p>{0} folder no longer exists on the network. Please review at your earliest convenience.</p>",
data);
mailBody.Append("<br/>");
mailBody.Append("<p>Thank you</p>");
mailBody.Append("<p>Development Team</p>");
mailBody.Append("</html>");
emailBody = mailBody.ToString();
另外请注意,你不需要,除非你打算传递参数到嵌入式字符串({0}
,{1}
等)在令牌使用AppendFormat方法。
嗨蒂姆,它工作时,我在这样的标签做了一个小的改变。感谢你的回答。 :)
请注意:
–