Home  >  Article  >  Web Front-end  >  In-depth analysis of commonly used header tags in the head tag

In-depth analysis of commonly used header tags in the head tag

青灯夜游
青灯夜游Original
2022-08-02 19:27:393403browse

In-depth analysis of commonly used header tags in the head tag

HTML 中的

标签是所有头部标签的容器,这些头部标签用来定义有关 HTML 文档的元数据(描述数据的数据)以及所需资源的引用(例如 CSS 样式文件、JavaScript 脚本文件),对文档能够在浏览器中正确显示起到了非常重要的作用。根据我们的需求,可以在 HTML 头部定义大量的元数据,也可以定义很少或者根本就不定义。虽然头部标签是 HTML 文档的一部分,但其中的内容并不会显示在浏览器中。

标签中可以使用的头部标签有 、<base>、<link>、<style>、<meta>、<script> 和 <noscript> 等,下面就来简单介绍一下它们。<p><span style="font-size: 18px;"><strong>1、<title> 标签<p><title> 标签用来定义 HTML 文档的标题,只有包含 <title> 标签的文档才算是一个有效的 HTML 文档。另外,一个 HTML 文档中仅允许存在一个 <title> 标签,并且 <title> 标签必须放置在 <head> 标签中。<p>注意,在 <title> 标签内部仅允许包含纯文本内容,不能包含其他 HTML 标签。<p><title> 标签的主要作用如下所示:<ul style="list-style-type: disc;"><li><p>在浏览器标题栏或者任务栏中显示标题;<li><p>当将页面添加到收藏夹(书签)时提供标题;<li><p>在搜索结果中显示页面标题。<p>下面的示例演示了如何在 HTML 文档中使用 <title> 标签:<pre class="brush:html;toolbar:false"><head> <meta charset="utf-8"> <title>php中文网-教程_手册_视频-免费php在线学习平台

In-depth analysis of commonly used header tags in the head tag

标签的内容必须与当前文档有关,并且不应该过长,中文页面请尽量控制在 30 个字符(包括空格)以内。<p><span style="max-width:90%"><strong>2、<base> 标签<p><base> 标签用于为页面中所有相对链接指定一个基本链接,当您设置了基本链接后,当前页面中的所有相对链接都会使用这个基本链接作为前缀,如下例所示:<pre class="brush:html;toolbar:false"><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title><base>标签演示

In-depth analysis of commonly used header tags in the head tag

上面的示例中第一个

  • 标签中的超链接会被解析为“//m.sbmmt.com/course.html”,第二个
  • 中的超链接会被解析为“//m.sbmmt.com/course/type/3.html”。

    注意,HTML 文档中的 标签必须出现在任何引用外部资源的标签之前,而且一个 HTML 文档中仅允许定义一个 标签。

    3、 标签

    标签经常用于引用外部 CSS 样式表, 标签中包含两个主要的属性,分别是 rel 和 href。rel 属性用来指示引用文件的类型,href 属性用来设置外部文件的路径。示例代码如下:

    
        此处书写标题
        
    
    

    HTML 标签中可以包含任意数量的 标签。

    扩展:引用外部 CSS 样式表有两种,link和@import

    • @import在

      简单实例:

      css外部样式表 style.css

      h1{
      	color:red;
      }
      p{
      	font-size:14px;
      	color:green;
      }

      HTML文档

      
      
      	
      		
      		
      		
      	
      

      link标签或@import的应用

      外部定义CSS样式表以.CSS为扩展名文件,然后在页面中通过link标签或@import链接到页面中。

      实现效果:

      In-depth analysis of commonly used header tags in the head tag

      link和@import的区别:

      1、从属关系区别

      @import是 CSS 提供的语法规则,只有导入样式表的作用;link是HTML提供的标签,不仅可以加载 CSS 文件,还可以定义 RSS、rel 连接属性等。

      2、加载顺序区别

      加载页面时,link标签引入的 CSS 被同时加载;@import引入的 CSS 将在页面加载完毕后被加载。

      3、兼容性区别

      @import是 CSS2.1 才有的语法,故只可在 IE5+ 才能识别;link标签作为 HTML 元素,不存在兼容性问题。

      4、DOM可控性区别

      可以通过 JS 操作 DOM ,插入link标签来改变样式;由于 DOM 方法是基于文档的,无法使用@import的方式插入样式。

      4、

      注意:对于文档中的唯一样式可以使用

      The above is the detailed content of In-depth analysis of commonly used header tags in the head tag. 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