0

enter image description here

Hi all,

I want to add style attributes in my HTML tags using C#. Please find the below code.

            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();

And the output is :

The text displayed in the image font style is "Time New Roman". How could I change that to display in any other font type. How could I add that in above HTML tags.

Thanks in advance.

0

5 Answers 5

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Tim, It worked when I made a small change in the tag like this. Thanks for the answer. :) <p><span style=font-family:calibri;>Please note:</span></p>
2

Add the style to the tag, like this:

<p style="font-family:courier">Please note:</p>

Check for more info here: http://w3schools.com/html/html_styles.asp

Comments

2
   <p style="font-family:arial black">Please note:</p> 

pls go through this link for more info

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

Comments

0

An even easier way would be to put it in the CSS

BODY P
{
}

Then you wouldnt need to put it into all the P tags

Or if you want to make it only apply to a section You should surround this in a div and then

.<DivClassName> P
{
}

Comments

0

I would do this, so you're taking advantage of CSS:

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();

Also note, you don't need to use the AppendFormat method unless you plan on passing in parameters into the tokens embedded in the string ({0}, {1} etc).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.