如何使用 HTMLTextWriter 创建间距和缩进?

发布于 2024-10-09 01:26:19 字数 501 浏览 8 评论 0原文

我想问如何使用 HTMLTextWriter 创建间距和缩进。 到目前为止,我已经尝试使用 html.writeline(); 但它不起作用。有人可以建议我有关代码吗?谢谢。

这是我目前拥有的代码:

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

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阿楠 2024-10-16 01:26:19

HtmlTextWriter 提供了两个选项来控制输出的缩进:

  • 其构造函数之一的 tabString 参数指定用于单级缩进的实际字符串(例如 >" " — 四个空格);
  • Indent 属性保存每行开头输出的缩进字符串数。

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.
江心雾 2024-10-16 01:26:19

在您正在编写的文本中添加  

Add   in the text you're writing.

春风十里 2024-10-16 01:26:19

我认为您的问题与其说是 MVC,不如说是对网站编码工作方式的理解。网页设计的一大推动力是所谓的内容与呈现的分离。这个想法是,网站上的所有信息(例如段落、标题、列表等)都应该与其向用户显示的方式分开。这种方法有很多优点:

  • 您可以以不同的方式向不同的用户显示相同的信息。例如,如果我从笔记本电脑访问您的网站,则页面看起来可能会与从手机访问时有所不同。

  • 如果您需要更改页面的外观,则只需更改页面的样式,而不是实际页面本身。

  • 您的页面可以应用多种不同的样式或外观。

  • 您可以在整个网站上使用一种风格的作品。这样您就不必重新设计每个页面的样式。

在当今的网络中,内容通常由 HTML 处理,样式由 CSS 完成。要了解 CSS 的强大功能(以及我正在讨论的示例),请查看 CSS Zen Garden< /a>.

您正在使用 MVC,它会生成 HTML,但 CSS 仍然应该是您处理布局的方式。我建议从 W3 Schools 的 HTMLCSS。祝你好运。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文