René's URL Explorer Experiment


Title: 【前端】【学习心得】第十三天 浅谈 BR 标签 · Issue #17 · paddingme/Learning-JavaScript · GitHub

Open Graph Title: 【前端】【学习心得】第十三天 浅谈 BR 标签 · Issue #17 · paddingme/Learning-JavaScript

X Title: 【前端】【学习心得】第十三天 浅谈 BR 标签 · Issue #17 · paddingme/Learning-JavaScript

Description: HTML 标签元素中
应用得场景并不多,我们是否真正了解
元素的语义,其正确使用场景,是否可以用 CSS 来改变其样式,用来清除浮动到底对不对?让我们慢慢剖析
元素,揭开它被忽视的面纱,一睹其神秘的容颜。 br 的语义 ,我们来看看 W3C 对
的定义。 The
element represents a line break. This element must be used only for line breaks that...

Open Graph Description: HTML 标签元素中
应用得场景并不多,我们是否真正了解
元素的语义,其正确使用场景,是否可以用 CSS 来改变其样式,用来清除浮动到底对不对?让我们慢慢剖析
元素,揭开它被忽视的面纱,一睹其神秘的容颜。 br 的语义 ,我们来看看 W3C 对
的定义。 The
element represents a line break. This elemen...

X Description: HTML 标签元素中<br>应用得场景并不多,我们是否真正了解<br> 元素的语义,其正确使用场景,是否可以用 CSS 来改变其样式,用来清除浮动到底对不对?让我们慢慢剖析<br> 元素,揭开它被忽视的面纱,一睹其神秘的容颜。 br 的语义 ,我们来看看 W3C 对 <br> 的定义。 The <br> element repres...

Opengraph URL: https://github.com/paddingme/Learning-JavaScript/issues/17

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"【前端】【学习心得】第十三天 浅谈 BR 标签","articleBody":"HTML 标签元素中`\u003cbr\u003e`应用得场景并不多,我们是否真正了解`\u003cbr\u003e` 元素的语义,其正确使用场景,是否可以用 CSS 来改变其样式,用来清除浮动到底对不对?让我们慢慢剖析`\u003cbr\u003e` 元素,揭开它被忽视的面纱,一睹其神秘的容颜。\n## br 的语义\n\n,我们来看看 W3C 对 `\u003cbr\u003e` 的定义。\n\n\u003e The `\u003cbr\u003e` element represents a line break.\n\u003e This element must be used only for line breaks that are actually part of the \n\u003e content:\n\u003e - poems\n\u003e - addresses\n\n由上可知: `\u003cbr\u003e`元素表示换行,它必须只能被使用作换行,实际上常用于是诗、地址的一部分。\n\n再来看 MDN 上的定义:\n\n\u003e The HTML `\u003cbr\u003e` Element (or HTML Line Break Element) produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.\n\u003e \n\u003e Do not use `\u003cbr\u003e` to increase the gap between lines of text; use the CSS margin property or the `\u003cp\u003e` element.\n\n意思基本一致:  `\u003cbr\u003e`元素(或 HTML 换行符元素)在文本中产生一个折行(回车)。对于写诗和地址,非常有用,行与行的划分变得明显。**不要使用 `\u003cbr\u003e` 来增加行与行之间的间隙**,应该使用 margin 属性或者`\u003cp\u003e`元素。\n\n另值得说明的是 \u003cbr\u003e 是个空元素,到底要不要闭合呢,答案是不需要 HTML5 规范中也推荐不闭合(待查)。\n## `\u003cbr\u003e` 的使用场景\n### 正确使用场景\n\n从上述`\u003cbr\u003e`的定义中, 我们可知 `\u003cbr\u003e` 元素的使用场景很明显,只适合在文本中折行,且这个折行的目的是为了文本本身的需要。例如:\n\n``` html\n    \u003cp\u003e\n        一二三四五,\n        \u003cbr\u003e\n        上山打老虎。\n        \u003cbr\u003e\n        老虎不在家,\n        \u003cbr\u003e\n        嗯哼就是他。\n    \u003c/p\u003e\n```\n\n效果是这样的,熟悉 Markdown 的同学知道如果文本想要换行可以连续打两个空格继续输入(待验证),其实这就是一个`\u003cbr\u003e`\n![ ](http://paddingme.qiniudn.com/21.PNG)\n### 错误使用场景一:用来增加文本行之间的间隙\n\n用来增加文本之间的间隙并不是它的应有用途。\n\n``` html\n\u003cp\u003e我想离一段文字远一点\u003c/p\u003e\n\u003cbr\u003e\n\u003cp\u003e我是一段被远离的文字\u003c/p\u003e\n```\n\n![](http://paddingme.qiniudn.com/22.PNG)\n\n这样使用是不对的,我们应该用 CSS 来做到增加多个文本间的距离(\"margin-botton\"或“margin-top”)。\n### 错误使用场景二: 用来清除浮动\n\n除了被用来增加上下文本间的间距,我们还有一个错误——用`\u003cbr\u003e`来清除浮动。\n\n``` html\n\u003cdiv style=\"float:left\"\u003e我向左浮动了\u003c/div\u003e\n\u003cbr style=\"\"\u003e\n```\n\n查是谁发明了br 用来清除浮动。\n\n首先这严重不符合`\u003cbr\u003e`的语义,其次当浮动元素小于`\u003cbr\u003e` 在浏览器中默认的高度时会出现一定的间隙,为了说清楚这个问题,我们来看个例子:\n\n``` html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eDocument\u003c/title\u003e\n    \u003cstyle\u003e\n    .box {\n        width:100px;\n        height: 100px;\n    }\n    .clear {\n        clear:both;\n    }\n    .red {\n        background-color: red;\n    }\n    .green{\n         background-color: green;\n    }\n    \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cdiv id=\"box1\"class=\"box red\"\u003e\u003c/div\u003e\n    \u003cbr\u003e\n    \u003cdiv id=\"box2\" class=\"box green\"\u003e\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n这里没有浮动只有一个换行符,我们可以看到效果是这样的:\n![](http://paddingme.qiniudn.com/hh.PNG)\n\n现在我们 box1 浮动;在上面代码中 设置 `#box1 {flat:left}` 看下效果:\n![](http://paddingme.qiniudn.com/bb.PNG)\n\n如上 box1 浮动导致 `\u003cbr\u003e` 和 box2 都上移。\n\n我们再给`\u003cbr\u003e`加上 `class=\"clear\"`\n![](http://paddingme.qiniudn.com/xx.PNG)\n\n这时候`\u003cbr\u003e`清除浮动 换行符去哪儿了,我猜换行符在红色下面被遮盖了,在清除浮动之前,浮动的影响还存在,`\u003cbr\u003e`clear之后影响才消除,所以 box2 才在下面的位置,意思即 `\u003cbr\u003e` 虽然清除了浮动但它是受到了浮动的影响的。这也是为什么用空元素进行清楚浮动的原因,以及伪元素 after 清楚浮动的原因(待验证)。\n\n`\u003cbr\u003e`在各浏览器有一定的高度。将浮动元素高度设定很低,box1 浮动,`\u003cbr\u003e` 清除 box1 浮动。\n\n``` html\n\u003cbody\u003e\n    \u003cdiv class=\"red\" style=\"float:left;width:10px;height:10px\"\u003e\u003c/div\u003e\n    \u003cbr class=\"clear\"\u003e\n    \u003cdiv class=\"box green\"\u003e\u003c/div\u003e\n\u003c/body\u003e\n```\n\n看下效果:\n![](http://paddingme.qiniudn.com/ss.PNG)\n\n`\u003cbr\u003e` 清除了浮动,仍然会占据一定的位置。可见这并没有达到我们想要的效果,我们想要的是 清除浮动元素之后,之后的元素可以正常紧挨着浮动元素(按正常 margin-top 计算 如果没有则紧挨),而现在凭白多了一段 `\u003cbr\u003e` 的间隙,准确的说是多了浏览器下`\u003cbr\u003e` 的高度减去浮动浮动的元素。\n\n综上我们要坚决抵制用 `\u003cbr\u003e` 来清除浮动,原因有三:\n- 增加了没有意义的标签,增加了代码量。\n- 不符合`\u003cbr\u003e` 的语义\n- 浮动元素高度小于浏览器下 `\u003cbr\u003e` 高度时,得不到我们想要的清除效果。\n\n好了今天就到这里,明天我们将来了解下  `\u003cbr\u003e`在各浏览器的表现,以及能不能使用 CSS 样式来改变其表现,能改变哪些样式,以及为什么只能改变这些样式,以及如何改变。\n","author":{"url":"https://github.com/paddingme","@type":"Person","name":"paddingme"},"datePublished":"2014-11-30T04:28:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/17/Learning-JavaScript/issues/17"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:65d40426-3ec4-1584-5aec-8b4f00c01bc0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id876A:209305:60AE9B:800E22:6A613E98
html-safe-nonceb8de39791f36ed99823a5dae392f0408131005c9b1e9a8c861e75c7680a69c2b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzZBOjIwOTMwNTo2MEFFOUI6ODAwRTIyOjZBNjEzRTk4IiwidmlzaXRvcl9pZCI6IjIyNjc3MTQ3NDY5NDg4MDkyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac92a99d44be09c5a7115c15d8d8cc415b397f5ca7b23973793197bca139743092
hovercard-subject-tagissue:50446649
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/paddingme/Learning-JavaScript/17/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7b3b1ae2101ed1ef8539402c143fb2f890bd705976a2f1de2aed377fa4b49281/paddingme/Learning-JavaScript/issues/17
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7b3b1ae2101ed1ef8539402c143fb2f890bd705976a2f1de2aed377fa4b49281/paddingme/Learning-JavaScript/issues/17
og:image:altHTML 标签元素中
应用得场景并不多,我们是否真正了解
元素的语义,其正确使用场景,是否可以用 CSS 来改变其样式,用来清除浮动到底对不对?让我们慢慢剖析
元素,揭开它被忽视的面纱,一睹其神秘的容颜。 br 的语义 ,我们来看看 W3C 对
的定义。 The
element represents a line break. This elemen...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamepaddingme
hostnamegithub.com
expected-hostnamegithub.com
None2b7a3d1e6770dc7153450d820fcfe9a7851c4cf2251dcc29c7ad3c5cd1b9e88b
turbo-cache-controlno-preview
go-importgithub.com/paddingme/Learning-JavaScript git https://github.com/paddingme/Learning-JavaScript.git
octolytics-dimension-user_id5771087
octolytics-dimension-user_loginpaddingme
octolytics-dimension-repository_id25473884
octolytics-dimension-repository_nwopaddingme/Learning-JavaScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id25473884
octolytics-dimension-repository_network_root_nwopaddingme/Learning-JavaScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release78cf9d43f120d1f03636ca22ab420bcbb1712804
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/paddingme/Learning-JavaScript/issues/17#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpaddingme%2FLearning-JavaScript%2Fissues%2F17
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpaddingme%2FLearning-JavaScript%2Fissues%2F17
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=paddingme%2FLearning-JavaScript
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/17
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/17
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/17
paddingme https://github.com/paddingme
Learning-JavaScripthttps://github.com/paddingme/Learning-JavaScript
Notifications https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Fork 13 https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Star 28 https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Code https://github.com/paddingme/Learning-JavaScript
Issues 30 https://github.com/paddingme/Learning-JavaScript/issues
Pull requests 0 https://github.com/paddingme/Learning-JavaScript/pulls
Actions https://github.com/paddingme/Learning-JavaScript/actions
Projects https://github.com/paddingme/Learning-JavaScript/projects
Wiki https://github.com/paddingme/Learning-JavaScript/wiki
Security and quality 0 https://github.com/paddingme/Learning-JavaScript/security
Insights https://github.com/paddingme/Learning-JavaScript/pulse
Code https://github.com/paddingme/Learning-JavaScript
Issues https://github.com/paddingme/Learning-JavaScript/issues
Pull requests https://github.com/paddingme/Learning-JavaScript/pulls
Actions https://github.com/paddingme/Learning-JavaScript/actions
Projects https://github.com/paddingme/Learning-JavaScript/projects
Wiki https://github.com/paddingme/Learning-JavaScript/wiki
Security and quality https://github.com/paddingme/Learning-JavaScript/security
Insights https://github.com/paddingme/Learning-JavaScript/pulse
【前端】【学习心得】第十三天 浅谈 BR 标签https://github.com/paddingme/Learning-JavaScript/issues/17#top
Mu-Help-Planhttps://github.com/paddingme/Learning-JavaScript/issues?q=state%3Aopen%20label%3A%22Mu-Help-Plan%22
https://github.com/paddingme
paddingmehttps://github.com/paddingme
on Nov 30, 2014https://github.com/paddingme/Learning-JavaScript/issues/17#issue-50446649
https://camo.githubusercontent.com/8b30e1cc0be8e35a4d92cb06f5e1d224cae8629a5fa6fc6379b4274a6ab9e9d0/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f32312e504e47
https://camo.githubusercontent.com/c457335a85739e69c69f240ddb02949b2d295af72840630c9609a7b690261682/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f32322e504e47
https://camo.githubusercontent.com/ce391a6cc86d37b09f7113120bc81c42d4580851837a7e2671fcef1b6b10a629/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f68682e504e47
https://camo.githubusercontent.com/71cc7651a76ac4e73fe91aa53bc18dde9f2a6cf12916424a2b728af2e3a2f4e1/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f62622e504e47
https://camo.githubusercontent.com/4f4762d76692333f709dd26dab4492552e4a37477249babf15a38966136a8bf6/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f78782e504e47
https://camo.githubusercontent.com/31bb8eda3b945710afe90ea46c86dfe4fbb904ede49d12610af1935062bf6aa1/687474703a2f2f70616464696e676d652e71696e6975646e2e636f6d2f73732e504e47
Mu-Help-Planhttps://github.com/paddingme/Learning-JavaScript/issues?q=state%3Aopen%20label%3A%22Mu-Help-Plan%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.