风格明朗< br>或填充/边缘元素 [英] Style-wise <br> or padding/margin elements

查看:140
本文介绍了风格明朗< br>或填充/边缘元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在使用HTML5和CSS3时,是否可以使用< br> 标签,当使用margin / padding时可以使用?

These days with HTML5 and CSS3, is the use of <br> tags frowned upon when margin/padding can be used?

编辑:这是关于我的用例的div元素之间的间距,但一般的最佳做法建议也是欢迎。

This is in regards to spacing between div elements for my use case, but general best practice advise is also welcome.

推荐答案

实际上,关于其使用方式的规则很明确,可追溯到 HTML的日子2.0

There are actually pretty well-defined rules around its usage, harking back to the days of HTML 2.0 when it was first introduced:


< BR> element指定单词之间的换行符(见6,字符,单词和段落)。例如:

The <BR> element specifies a line break between words (see 6, "Characters, Words, and Paragraphs"). For example:

<P> Pease porridge hot<BR>
Pease porridge cold<BR>
Pease porridge in the pot<BR>
Nine days old.


< br& code>元素本身从来不打算用于控制margin / padding。虽然他们在HTML 3.2中引入了一个表示的清除属性来处理浮动图像等内容,但是很快就在HTML 4和XHTML 1中弃用了CSS,

The <br> element itself was never intended to be used to control margin/padding. Although they introduced a presentational clear attribute to HTML 3.2 to handle things like floating images, it was soon deprecated in HTML 4 and XHTML 1 in favor of CSS. That was almost 15 years ago, so it's really nothing new.

HTML5 ,他们更清楚地表明< br> 不适用于演示或布局,并附有示例(和 清除 attribute is obsolete ):

In HTML5, they've made it much clearer that <br> isn't intended for presentation or layout, with examples (and the clear attribute is obsolete):


br 元素必须


以下示例是正确使用

The following example is correct usage of the br element:

<p>P. Sherman<br>
42 Wallaby Way<br>
Sydney</p>


br 元素不能用于分隔段落中的主题组。

br elements must not be used for separating thematic groups in a paragraph.


以下示例不符合规定, c $ c> br 元素:

<p><a ...>34 comments.</a><br>
<a ...>Add a comment.</a></p>
<p><label>Name: <input name="name"></label><br>
<label>Address: <input name="address"></label></p>

以下是上述的替代方法,它们是正确的:

Here are alternatives to the above, which are correct:

<p><a ...>34 comments.</a></p>
<p><a ...>Add a comment.</a></p>

<p><label>Name: <input name="name"></label></p>
<p><label>Address: <input name="address"></label></p>



$ c>< br> 代替CSS边距的布局目的一直被皱眉,至少由编写规范的人。

So using <br> in lieu of CSS margins for layout purposes has always been frowned upon, at least by the people who wrote the specifications.

这篇关于风格明朗&lt; br&gt;或填充/边缘元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆