处女贴,问个很浅薄也很困扰的问题吧发现官方草案及答疑中说明即自关闭的斜线(/)对空标签无效,普通HTML标签不要自闭合才是标准的写法,那么我们是否还应该闭合html5中的空标签?看了下SF的源码,也并不是所有的单标签都闭合了:)Then,iftheelementisoneofthevoidelements,oriftheelementisaforeignelement,thentheremaybeasingleU+002FSOLIDUScharacter(/).Thischaracterhasnoeffectonvoidelements,butonforeignelementsitmarksthestarttagasself-closing.VoidelementsinHTML(e.g.thebr,imgandinputelements)donotrequireatrailingslash.e.g.Insteadofwriting,youonlyneedtowrite.ThisisthesameasinHTML4.However,duetothewidespreadattemptstouseXHTML1,thereareasignificantnumberofpagesusingthetrailingslash.Becauseofthis,thetrailingslashsyntaxhasbeenpermittedonvoidelementsinHTMLinordertoeasemigrationfromXHTML1backtoHTML.
2 回答

猛跑小猪
TA贡献1858条经验 获得超8个赞
这个网站有的闭合,有的没闭合,可能不是一个人写的,不然不会产生两种风格。关于空标签闭合,我偏向GoogleStyleGuide中建议的不闭合,在这方面我有点偷懒,觉得Google的标准就是业界今后的标准。有点完美主义,以前力求闭合,现在力求不闭合。
添加回答
举报
0/150
提交
取消