【发布时间】:2017-07-06 09:27:16
【问题描述】:
我找不到关于如何在多行上缩进 HTML 标记的指南,而且我目前使用的解决方案并不能真正让我满意。
假设我们有一个非常长的div 声明,例如:
<div data-something data-something-else data-is-html="true" class="html-class another-html-class yet-another-html-class a-class-that-makes-this-declaration-extremely-long" id="just-a-regular-id">
为了避免在发现这些大行时水平滚动,我通常采用以下方式缩进:
<div
data-something
data-something-else
data-is-html="true"
class="html-class another-html-class yet-another-html-class a-class-that-makes-
this-declaration-extremely-long"
id="just-a-regular-id"
>
<p>Some element inside the DIV</p>
</div>
我认为在可读性方面效果很好,但我有些担心。
- 这种方式被认为是一种好的做法吗?
- 您是否会发现将结束的
>留在与最后一个元素内联的开始 HTML 标记中,或者像我在上面的示例中所做的那样位于新行上? - 您还有其他首选方式来处理超长 HTML 声明吗?
如果您知道一些涵盖此特殊情况的 HTML 样式指南的好资源,请随时分享,因为我没有在网上找到任何具体的内容。
【问题讨论】:
标签: html coding-style indentation