您应当避免的 12 个 HTML 标签错误 - zzzz~~~'s Blog

您应当避免的 12 个 HTML 标签错误

zzzz~~~ posted @ 2013年1月24日 15:20 in WEB , 1922 阅读

您应当避免的 12 个 HTML 标签错误

Author: Yugang LIU
Date: 2012-10-3
Category:WEB
Tags:html

From: 12 Evil HTML Tag Mistakes You Really Should Avoid.

在 WEB 页面访问中,人们经常遇到 HTML 代码编写错误,开发者应当真正的认真考虑并小心使用 HTML 标签。下面讨论了 12 个常见的易忽略的错误,这些提示将会有助于 HTML 开发者。

1. HTML 标签嵌套错误

12_html_tag_mistakes/highlighting_tag_tree1.png

关闭 HTML 标签十分重要。标签的开启与关闭要一一对应,而且顺序相反。新手往往不在意标签的关闭。校验 HTML 代码时会发现错误,并且 Style 样式也不能正确提交。一定要小心这个错误。

错误用法:

<div><p><a>This is my Smashing text</p></div></a>

正确用法:

<div><p><a>This is my Smashing text</a></p></div>

2. 不正确的使用 List

12_html_tag_mistakes/HTML_Lists1.png

OL 和 UL 标签总是被用于显示多个项目,并以不同的方式使用。List 标签在显示大量信息时特别有用,它能避免使用大量的换行符( <br /> ),搜索引擎也能识别 List 标签,使用标准的 HTML 标签会比 <br /> 做得更好。

3. 不正确的使用 Form 标签

form 和 table 标签常常使人迷惑。是应当先用 table,还是先用 form,请看下面:

错误用法:

<table><form><tr><td>..... </td></tr></form></table>

正确用法:

<form><table><tr>.... </tr></table></form>

4. 在 inline 元素中使用 block 元素

12_html_tag_mistakes/inline-block.gif

HTML 开发者都知道元素总是以 inline 或 block 的方式显示,每一个元素缺省被创建在 inline 或 block 元素内。在文档中,首先是 block 元素,如 <p> 和 <div> 等,inline 元素则在 block 元素内。整个文档由若干个这种结构体组成。因此,要确保 inline 元素放在 block 元素内,而不是其他地方。

block 元素:

<div>, <h1>…<h6>, <p>, <ul>, <ol>, <dl>, <table>, <blockquote>, <form>

inline 元素:

<span>, <a>, <strong>, <em>, <img />, <abbr>, <acronym>

5. 缺少 alt 属性

当使用图像并显示在主页时,一定要使用 alt 属性。这是非常必要的,用户可以决定是否显示图像,特别是在一个慢速连接或小屏幕时。这个属性能描述所显示的图像。不要使用 alt="image"alt="" ,这没有任何益处。

错误用法:

<img src="smiley.gif" alt="" />

正确用法:

<img src="smiley.gif" alt="Smiley face" width="42" height="42" />

6. 粗体和斜体的使用方法错误

一般 <b> 用于粗体, <i> 用于斜体,但这两种表示方法只是计算机语法,用 CSS 样式来表达会更好一些。如果文本必须使用粗体或斜体,那么使用 <strong><em> ,他们与 <b><i> 的功能一样,但看上去更好。

7. 不必要的换行

在一段中,使用标签 <br /> 来换行。但是许多人在两个元素间加入换行,这是不对的。只有在必要时,才用 <br /> 切换到下一行。

错误用法:

This is my first paragraph
<br />
<br />
<br />

This will be my test description

正确用法:

<p>This is my first paragraph</p>
<p>This will be my test description</p>

8. 不正确的使用删除线

12_html_tag_mistakes/strikethrough1.jpg

<strike><s> 曾用于修正 WEB 中的文本,但是现在,他们已经废除了。新的标签是 <ins><del> 。他们用于 WEB 页和文档中的插入和删除。

9. 在 HTML 代码中使用 CSS 样式

你应当听说过许多次,在 HTML 代码中使用 CSS 样式不是个好注意,你知道为什么吗?这是因为 CSS 样式和 HTML 代码是完全分离的,他们共同组成结构化文档。在 HTML 代码中直接使用样式是不正确的。这就是为什么总是建议在样式表中表达样式。

错误用法:

<p style="font-size: 14px;font-weight: bol">

10. 包含和去除边框

边框属性是一个表示效果,因此它只应当被 CSS 样式修改。不要担心默认的边框样式。

错误用法:

<img src="smiley.gif" alt="" border="0" />

11. 忽略 <h1>..<h6> 标签

<h1>..<h6> 标签用于文档识别,它创建一个区段。有时 <h> 标签会出现在文档右侧,这依靠于您的文档的组织方式。如果能按顺序使用则更好。

错误用法:

<strong>This is my Smashing Heading</strong><p>This is my xyz description.</p>

正确用法:

<h1>This is my Smashing Heading</h1><p>This is my xyz description.</p>
Avatar_small
sofa cleaning dubai 说:
2019年11月28日 13:28

All of our office cleaning up services will be unique once we do never take a performance, level of quality service transport, and practices with levity during WhiteSpot Cleaning up Services. Most people ensure all of requests to get office cleaning up services will be treated by using urgency, and all of our clients will be assured this their requests might be treated in just fifteen a matter of minutes.

Avatar_small
house maid services 说:
2021年1月29日 19:48

House maid agencies Asia for the reason that common decision. Often, agencies by Asia are classified as the top number of other employers in the world. Aside on the lower expenses, these firms work closely while using the popular maids and in addition they know who definitely are the knowledgeable ones along with the maids value trusting. Usually most of these agencies originated from Hong Kong in addition to Singapore in addition to these places operate globally beneath strict rules in their government.

Avatar_small
painting company in 说:
2021年7月01日 18:33

The type of home-based business that comes to mind is the trade of house painting. It's a proven fact that one way to success is performing a site that most people will happily purchase. The house painting business is usually a perfect fit given that it can be started either on a part time basis or full time. Certainly one of the requirements will be the business owner has got to learn how to paint. Though some might like to say it should take many years to perfect a respectable trade such as painting, that really isn't true any longer.

Avatar_small
part time maids in d 说:
2021年8月26日 16:38

Cleaning up Services around Dubai is actually a blessing for anyone residents plus expats. Keeping fine hygiene is definitely hectic for every individual in a busy agenda. So it’s better to hire a reliable and probably the greatest cleaning providers in Dubai. When hiring all these experts, you may relax when professional carpet cleaners make a person's cleaning for yourself.

Avatar_small
part time maids in d 说:
2021年10月02日 16:52

Once you think regarding home washing companies, you may be thinking that everything that these organizations offer are usually standard services for instance dusting and also vacuuming. This is simply not the circumstance, though. In reality, you can easily hire an organization like this kind of for various types of household obligations. One with the types regarding duties they can assist together with is firm. If you might be a extremely unorganized particular person and don't know how to have your residence organized, it is possible to hire a specialist for aid. This just isn't something that you need to be embarrassed to accomplish. It can actually change your daily life, your mood and lots of other items.

Avatar_small
word hurdle 说:
2022年9月21日 14:41

Word Hurdle is a fun and free way to challenge your mind and unwind.

Avatar_small
cookie clicker unblo 说:
2022年10月13日 22:31

Thank you for sharing this knowledge with me. The content of your blog is excellent. You allowed others to read a really informative and entertaining blog post you wrote.

Avatar_small
1v1.lol unblocked 说:
2023年3月25日 14:50

It's a huge relief to have access to reliable cleaning services in Dubai, both for locals and visitors. Everyone has a busy schedule, which makes it difficult to maintain good personal hygiene. So, it is recommended that you employ the services of one of the best cleaning companies in Dubai.

Avatar_small
globle 说:
2023年6月01日 19:28

Excellent piece, and the insights you've shared are both fascinating and helpful to me. Your post has provided me with a wealth of information. I really hope that you will be publishing more fresh posts in the not too distant future!

Avatar_small
free games 说:
2023年6月07日 12:19

Does it encounter any errors?

Avatar_small
maid services dubai 说:
2023年8月31日 18:48

There definitely isn't a more pleasurable feeling as opposed to coming home for a spotless residential home, particularly when another did every bit of the; there isn't actually anything left for you to do but work out in a hammock in your sun! Aided by the hectic lifestyle nearly everybody have not to mention both wifes working, there are many find they can't have long left for the purpose of domestic routine service. Before you have a look at Web or call up somewhere to defend myself against a cleaning service.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee