Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

html - HTML 5:是 <br> , <br/> , 要么 <br /> ?(HTML 5: Is it <br>, <br/>, or <br />?)

I've tried checking other answers , but I'm still confused — especially after seeing W3schools HTML 5 reference .

(我尝试检查其他答案 ,但仍然感到困惑-特别是在看到W3schools HTML 5参考之后 。)

I thought HTML 4.01 was supposed to "allow" single-tags to just be <img> and <br> .

(我认为HTML 4.01应该“允许”单个标签为<img><br> 。)

Then XHTML came along with <img /> and <br /> ( where someone said that the space is there for older browsers ).

(然后XHTML与<img /><br />有人说那里是旧浏览器的空间 )。)

Now I'm wondering how I'm supposed to format my code when practicing HTML 5.

(现在,我想知道练习HTML 5时应该如何格式化代码。)

Is it <br> , <br/> or <br /> ?

(是<br><br/>还是<br /> ?)

  ask by Eikern translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Simply <br> is sufficient.

(只需<br>就足够了。)

The other forms are there for compatibility with XHTML;

(还有其他形式是为了与XHTML兼容。)

to make it possible to write the same code as XHTML, and have it also work as HTML.

(使编写与XHTML相同的代码成为可能,并使它也可以用作HTML。)

Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare <br> tag;

(某些生成HTML的系统可能基于XML生成器,因此不能仅输出裸<br>标记。)

if you're using such a system, it's fine to use <br/> , it's just not necessary if you don't need to do it.

(如果您使用的是这样的系统,则可以使用<br/> ,如果您不需要这样做,则没有必要。)

Very few people actually use XHTML, however.

(但是,实际上很少有人使用XHTML。)

You need to serve your content as application/xhtml+xml for it to be interpreted as XHTML, and that will not work in old versions of IE - it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML.

(您需要将内容作为application/xhtml+xml进行提供,才能将其解释为XHTML,这在旧版本的IE中将不起作用-这也意味着您犯的任何小错误都将阻止您的页面在浏览器中显示确实支持XHTML。)

So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML.

(因此,Web上看起来像XHTML的大多数东西实际上都是作为HTML提供和解释的。)

See Serving XHTML as text/html Considered Harmful for some more information.

(有关更多信息,请参见将XHTML作为text / html认为有害 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...