How can I create spacing and indents using HTMLTextWriter?
I would like to ask how do I create a spacing and indent using HTMLTextWriter
.
So far, I have tried using the html.writeline();
but it does not work. Can someone advise me on the codes? Thanks.
Here is the code that I currently have:
HtmlTextWrite开发者_StackOverflowr html = new HtmlTextWriter(new StreamWriter(textBoxSave.Text)); //change to directory
html.RenderBeginTag("html");
html.AddAttribute("style", "background-color: white; color: black; font-size: small;");
html.WriteFullBeginTag("body");
html.WriteEndTag("body"); // body
html.RenderEndTag(); // html
html.Close();
HtmlTextWriter
provides two options to control indenting of the output:
- the
tabString
argument of one of its constructors specifying the actual string to be used for a single level of indentation (e.g." "
— four spaces); - the
Indent
property that holds the number of indent strings to be output at the beginning of each line.
Add
in the text you're writing.
I think your problem here isn't so much MVC as an understanding of the way website coding works. The big push in web design is something called separation of content from presentation. The idea is that all of the information on your website (such as paragraphs, headers, lists, etc) should be separate from how it's displayed to the user. This approach has a lot of advantages:
You can display the same information differently to different users. For instance, if I access your website from a laptop, the page can look different then if I access it from a mobile phone.
If you need to make a change to the way your page looks, you only have to change the styling of your page, not the actual page itself.
Your page can have multiple different styles, or skins, applied to it.
You can have one style work across an entire site. This prevents you from having to restyle every page you make.
With today's web, content is usually handled by HTML and styling is done by CSS. For a look at how powerful CSS can be (and an example of what I'm talking about), check out CSS Zen Garden.
You're using MVC, which generates HTML, but CSS should still be the way you handle layout. I'd recommend starting with W3 Schools' lessons on HTML and CSS. Good luck.
精彩评论