2011-11-16 62 views
0

enter image description here從代碼添加樣式屬性的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標籤中添加。

在此先感謝。

回答

2
<p><span style="font-family:Verdana">Please note:</span></p> 

http://www.w3schools.com/html/html_styles.asp

+0

嗨蒂姆,它工作時,我在這樣的標籤做了一個小的改變。感謝你的回答。 :)

請注意:

0

一個更簡單的方法是將其放在CSS

BODY P 
{ 
} 

然後你不會需要把它變成所有P標籤

或者,如果你想只有它適用於部分 你應該在一個div圍繞這一點,然後

.<DivClassName> P 
{ 
} 
0

我會做到這一點,那麼你正在採取的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方法。