何时使用< br>换行与CSS定位? [英] When to use <br> line breaks vs CSS positioning?

查看:244
本文介绍了何时使用< br>换行与CSS定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常想知道如何正确使用< br> 换行符。似乎它们经常被错误地用于定位或清除应该使用CSS的内容。

I've often wondered about the proper use of a <br> line break. Seems that often they are incorrectly used for positioning or clearing content where CSS should instead be used.

W3schoools.org表示对空行使用< br> ,但对创建或分隔段落。查看 W3C HTML5规范草稿,可以更清楚地看到<$ c当内容需要换行时将使用$ c>< br> ,例如作者想要的诗歌的地址行或空白行。

W3schoools.org says to use <br> for blank lines, but not for creating or separating paragraphs. Looking over W3C HTML5 spec draft, it's a little clearer that the <br> would be used when content requires a line break such as lines of an address or blank lines in poetry, where intended by the author.

但我仍然对任何进一步的澄清或输入任何人感兴趣。我经常发现自己选择不使用< br> 标签,而只是使用所需的清除,边距,填充等来设置元素,以创建所需的空间。

But I'm still interested in any further clarification or input anyone else. I often find myself opting not to use <br> tags but instead just styling elements with the desired clears, margins, paddings, etc to create the space desired.

不是说这是至关重要的,但是这里的例子让我想到一个流行的(权威的)网站使用< br> / code>,我不知道是相当语义。这里我刚刚通过CSS清除了< a> 的兄弟姐妹:

Not that it's supremely important, but here's the example that got me thinking about this where a popular ("authoritative") site used a <br> that I'm not sure is quite semantic. Here I would've just cleared the <a> from it's siblings via CSS:

<p>Lorem ipsum dolor sit amet, consectetur tempor laborum.</p>
<br>
<a href="#readmore">more &gt;&gt;</a>


推荐答案

表示新行。在段落之间添加换行符被用于当天,当HTML看起来像Chop Suey,并且HTML文档的语义看起来像是来自学龄前使用Dreamweaver的人。

To me, linebreaks should only be used inside paragraphs to indicate a new line. Adding line-breaks between paragraphs was used back in the day, when HTML looked like Chop Suey and the semantics of the HTML document looked like someone from preschool used Dreamweaver.

I个人依赖边距和填充进行内容分离,如果我必须使用< br /> 这意味着我做错了。我认为地址行是正确使用的一个完美的例子,我会坚持只有这些情况。

I personally rely on margins and padding for content separation, if I have to use a <br /> it means I've done something wrong. I think lines of an address are a perfect example of proper usage and I would stick to only those scenarios.

这篇关于何时使用&lt; br&gt;换行与CSS定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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