我有一些冗长的HTML,这超过了我的项目的80个字符的限制。我们有一个样式指南,它限制了每行的字符数,这很好,因为现在这行运行得太长了,如果不向右滚动,你就看不到它。
<div id="email-signup-container">
<div id="mc_embed_signup">
<div class="interested">
<div class="container">
<div class="left col-lg-6 col-md-6 col-sm-12 col-xs-12">
<h3>Help New York residents keep the heat on this winter.</h3>
<a href="http://www.nycharities.org/donate/charitydonate.asp?ID=4081" class="donate-btn btn-interest">DONATE</a>
</div>
<div class="right col-lg-6 col-md-6 col-sm-12 col-xs-12">
<h3>Without heat? Visit our resources page.</h3>
<a class="btn-interest" href="resources">RESOURCES</a>
</div>
</div>
</div>
</div>
</div>
不幸的是,我找不到任何涵盖多行HTML的样式指南。我在一个项目中工作过,我们通过属性更新了一些东西,但它是有争议的:
<a
href="http://www.nycharities.org/donate/charitydonate.asp?ID=4081"
class="donate-btn btn-interest">DONATE</a>
有些人想把结束语放在下面这样的新行上:
<a
href="http://www.nycharities.org/donate/charitydonate.asp?ID=4081"
class="donate-btn btn-interest"
>DONATE</a>
其他人希望结束标记与开始标记处于同一级别:
<a
href="http://www.nycharities.org/donate/charitydonate.asp?ID=4081"
class="donate-btn btn-interest"
>
DONATE
</a>
我有点讨厌他们所有人。有没有人能指出一些已发布的风格指南,这些指南涵盖了这一点,这样我们就可以采用一个,然后继续前进?
发布于 2016-02-08 23:26:13
我也一直在想这一点。我唯一能找到的就是the guide from GoCardless,上面写着:
<!-- Try using line-breaks for multiple attributes, keeping the first attribute
on the tag's opening line -->
Good:
<div custom-attribute
class="something"
role="something-else"></div>
<!-- The closing tag ^^^ can stay on the same line for empty elements-->
<div custom-attribute
class="something"
role="something-else">
··Foo <!-- Otherwise nest plz -->
</div>
发布于 2017-11-21 23:44:34
没有一个明确的答案,但我想补充另一个建议:属性缩进两次,内容只缩进一次。
举个例子:
<a
href="http://www.nycharities.org/donate/charitydonate.asp?ID=4081"
class="donate-btn btn-interest">
DONATE
</a>
对于a
标签,这看起来很奇怪,但是对于更长的标记名,就像Angular中常见的那样,它看起来很好:
<my-component
attribute1="val"
attribute2="val2"
attribute3="etc">
<span>Hello :)</span>
</my-component>
https://stackoverflow.com/questions/31103886
复制相似问题