Home >Web Front-end >HTML Tutorial >Semantize your HTML tags and attributes

Semantize your HTML tags and attributes

巴扎黑
巴扎黑Original
2017-04-05 16:52:291034browse

Another important aspect of separating structure and presentation is the use of semantic markup to structure document content. The presence of an XHTML element means that the portion of the marked content has a corresponding structural meaning, and there is no reason to use other markup. In other words, don't let CSS make one HTML element look like another HTML element, such as using

instead of a

tag heading.

The first is about the difference between semantics and default styles. The default style is the expression of some commonly used tags set by the browser. Personally, I think its main purpose is to let everyone intuitively understand markup and attributes. Purpose and function, it is obvious that the Hx series looks a lot like the title, because of the bold and larger font size. , are used to distinguish them from other words and play a role in emphasis. Lists and tables clearly tell you what they do.

Secondly, the most important benefit of semantic web pages is that they are friendly to search engines. With good structure and semantics, your web content will naturally be easily crawled by search engines, and you can save a lot of effort in promoting your website.

,

,

,

,

,
, are used as titles, in descending order of importance.

is the highest level. For example:

<h1>文档标题</h1>
<h2>次级标题</h2>

Instead of using

Document Title

, or Document Title. Obviously search engines will not use the latter. Think he's the one in the title.

Paragraph mark, after knowing

as a paragraph, you will no longer use
to break lines, and there is no need for

to distinguish paragraphs from paragraphs. The text in

will wrap automatically, and the line wrapping effect is better than
. The gaps between paragraphs can also be controlled using CSS, making it easy and clear to distinguish paragraphs from each other. Using line-height can easily define the spacing between lines, and then define effects such as drop caps, which is perfect. For example:

<p>Admin10000.com 是WEB开发者学习交流的网站,这里提供大量实用的技术文档及相关资源下载,是网页设计、网络编程人员及其爱好者必备网站。</p>
<p>希望大家能在这里学到WEB开发知识,启发灵感,提高自己的WEB开发水平。</p>

    Unordered lists are so common that they are widely used by everyone,
      Ordered lists are also quite commonly used. In the process of web standardization,
        is also used more in navigation bars. Originally, the navigation bar was a list. This is completely correct, and when your browser does not support CSS, the navigation links are still very convenient. It works fine, but the aesthetics are a bit off. For example:

        <ul>
            <li>项目一</li>
            <li>项目二</li>
            <li>项目三</li>
        </ul>
        <ol>
            <li>第一章</li>
            <li>第二章</li>
            <li>第三章</li>
        </ol>

        ,
        ,

        dl is "definition list". For example, this kind of list can be used for the explanations and definitions of words in the dictionary. For example:

        <dl>
        <dt>Dog</dt>
        <dd>A carnivorous mammal of the family Canidae.</dd>
        </dl>
        <dl>
            <dt>上海滩</dt>
            <dd>这部拍摄于1980年的《上海滩》堪称是香港电视史上最成功、最经典的剧集。
            当年在香港播出以后,产生了巨大的轰动效应。</dd>
            <dt>周润发</dt>
            <dd>和所有伟大的影星一样,周润发印证了一个时代,一个香港电影的黄金时代。
        风衣墨镜、冷血双枪、阳光微笑,都封存胶片之中,当我们回首寻望的时候,发哥已被刻为一个时代的坐标。</dd>
        </dl>

        , cite, ,

        Forums and blogs often use to mark short single-line quotes when quoting others. Web browsers will automatically recognize content between . Unfortunately, IE doesn't recognize it, and sometimes, can cause some accessibility issues. Because of this, some people recommend that you avoid using and manually insert citation tags. By adding a single line of reference content to a containing the appropriate class, you can style the reference with CSS, but this has no semantic meaning. You can read The Q tag (http://peintomark.org/archives/2002/05/04/the_q_tag) written by Mark Pilgrim for his views on dealing with related issues. For long quotes of one or more paragraphs, use

        . CSS can be used to define styles for references. Note that a paragraph of article cannot be placed directly in
        , the quoted content must also be included in an element, usually

        . The cite attribute can be used with both and

        to provide the source address of the quoted content. It should be noted that if you use instead of tag to quote content, then you cannot use the cite attribute. For example:

        <cite>Designing with Web Standards</cite> is an excellent book by Jeffrey Zeldman.
        <p> <cite>孔子</cite>曰:<q>学而不思则罔,思而不学则殆</q>.</p>
        <p>The W3C says that <q cite="http://www.w3.org/TR/REC-html40/
        struct/text.html#h-9.2.1">The presentation of phrase elements
        depends on the user agent.</q>.</p>
        <blockquote cite="http://www.w3cn.org/">
            <p>“我们大部分人都有深刻体验,每当主流浏览器版本的升级,我们刚建立的网站就可能变得过时,我们就需要升级或者重新建造一遍网站。例如1996-1999年典型的"浏览器大战",为了兼容 Netscape 和 IE,网站不得不为这两种浏览器写不同的代码。同样的,每当新的网络技术和交互设备的出现,我们也需要制作一个新版本来支持这种新技术或新设备,例如支持手机上网的 WAP 技术。类似的问题举不胜举:网站代码臃肿、繁杂浪费了我们大量的带宽;针对某种浏览器的 DHTML 特效,屏蔽了部分潜在的客户;不易用的代码,残障人士无法浏览网站等等。这是一种恶性循环,是一种巨大的浪费。”</p>
        </blockquote>

        是用作强调的,是用作重点强调的。 大部分浏览器用斜体显示强调的内容,用粗体来显示重点强调的内容,然而,这是没有必要的,如果是为了确定强调内容的显示方式,最好的方法就是使用CSS来定义他们的表现。当你想要的只是视觉上的效果时,就不要使用强调了。而且如果你想要强调但是还觉得粗体或者斜体不视觉效果没那么好,特别是斜体对于中文来说,那么你完全可以定义一些其他的比较醒目的样式达到强调的效果。例如:

        <p><em>强调</em> 的文本通常用斜体显示,
        然而,<strong>特别强调</strong> 的文本通常以粗体显示。</p>

        、标签为表格头部,标签为表格主体内容,标签为表格尾部。
        其中还可以使用scope 可用于取代headers属性,标记含有表头信息的单元格,其中各数值的内容如下:
         row 指示当前单元格,为包含当前单元格的行提供相关的表头信息。
         col 指示当前单元格,为根据当前单元格指定的列提供相应的表头信息。
         rowgroup 指示当前单元格,为包含当前单元格的其余行组提供相关的表头信息。
         colgroup 指示当前单元格,为根据当前单元格指定的其余列组提供相应的表头信息。
        abbr 用于定义表头单元格中的缩写名,如果没有定义该属性,则将默认单元格内容为节略形式。
        例如:

        <table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">
        <caption>Table 1: Power Mac G5 tech specs </caption>
          <tr>
            <th scope="col" abbr="Configurations" class="nobg">Configurations</th>
        
            <th scope="col" abbr="Dual 1.8">Dual 1.8GHz</th>
            <th scope="col" abbr="Dual 2">Dual 2GHz</th>
                <th scope="col" abbr="Dual 2.5">Dual 2.5GHz</th>
          </tr>
          <tr>
            <th scope="row" abbr="Model" class="spec">Model</th>
            <td>M9454LL/A</td>
        
            <td>M9455LL/A</td>
            <td>M9457LL/A</td>
          </tr>
          <tr>
            <th scope="row" abbr="G5 Processor" class="specalt">G5 Processor</th>
            <td class="alt">Dual 1.8GHz PowerPC G5</td>
            <td class="alt">Dual 2GHz PowerPC G5</td>
        
            <td class="alt">Dual 2.5GHz PowerPC G5</td>
          </tr>
          <tr>
            <th scope="row" abbr="Frontside bus" class="spec">Frontside bus</th>
            <td>900MHz per processor</td>
            <td>1GHz per processor</td>
            <td>1.25GHz per processor</td>
        
          </tr>
          <tr>
            <th scope="row" abbr="L2 Cache" class="specalt">Level2 Cache</th>
            <td class="alt">512K per processor</td>
            <td class="alt">512K per processor</td>
            <td class="alt">512K per processor</td>
          </tr>
        
        </table>

        <p><dfn title="Microsoft web browser">Internet Explorer</dfn> is the most popular browser used underwater.</p>

         

        ,

        知道del,就不要再用做删除线了,用del显然更具有语义化。而且del还带有cite和datetime来表明删除的原因以及删除的时间。ins是表示插入,也有这样的属性。例如:

        <p>It really was <ins cite="rarara.html" datetime="20031024">very</ins> good.</p>

        表示是计算机代码。而默认样式为打字体。技术论坛和blog中经常遇到。例如:

        标签是表示web页面上的简称,标签为取首字母缩写。(注:这里把简称和缩写分开而论,简称范围比缩写大,取首字母的缩写用标签)Windows的IE6.0以下的浏览器暂不支持标签。 在IE里,你可以应用CSS给但是不能应用给标签,IE会为标签的title属性显示提示,但是会忽略标签。
        解决方法见: http://www.w3cn.org/article/translate/2005/115.html
        例如:

        <abbr title="Cascading Style Sheets">CSS</abbr>
        <acronym title="Cascading Style Sheets">CSS</acronym >

        alt属性和title属性

        title属性用来为元素提供额外说明信息title属性可以用在除了base,basefont,head,html,meta,param,script和title之外的所有标签。但是并不是必须的。
        alt属性为不能显示图像、窗体或applets的用户代理(UA),指定替换文字。替换文字的语言由lang属性指定。
         

        <img src="/img/common/logo.gif" width="90" height="27" alt="bluediea.com">
        <a href="http://www.jluvip.com/blog/article.asp?id=260" title="js获取单选按钮的数据">js获取单选按钮的数据</a>

        The above is the detailed content of Semantize your HTML tags and attributes. For more information, please follow other related articles on the PHP Chinese website!

        Statement:
        The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
        、< caption >、 summary

        XHTML中的表格不应用来布局。然而如果是为了标记列表的数据,就应该使用表格了。

        为表格标题,属性summar为摘要,
        标签为首部说明,