深圳网站建设

网站建设资讯

为您提供网站建设行业资讯、网站优化知识、主机域名邮箱、网站开发常见问题等。

HTML中head元素常用标签介绍

2021-01-09 1541 编辑:光有网络 来源:互联网

  <head>元素是所有头部元素的容器,<head>内的元素可以指示浏览器在何处可以找到样式表,提供一些信息等。head内常用的元素有<title>、<base>、<link>、<meta>、<script>及<style>。


1、<title>标签定义文档的标题


  title元素在所有的HTML文档中都是必须的,它定义浏览器地址栏中显示的标题,实例如下

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
</head >
</html>

2、<base>标签为页面上所有链接规定默认地址或默认目标(target)

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
    <!-- 规定默认地址-->
    <base href="http://www.baidu.com"></base>
    <!-- 规定默认目标-->
    <base target="_blank"></base>
</head >
</html>

3、<link>标签定义文档与外部资源之间的联系,它最常用于连接样式表

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
    <!-- 规定默认地址-->
    <base href="http://www.baidu.com"></base>
    <!-- 规定默认目标-->
    <base target="_blank"></base>
    <!-- 连接样式表-->
    <link rel="stylesheet" type="text/css" href="mystyle.css">
</head >
</html>

4、<meta>元素常用于描述页面功能、关键词、文档作者、创建时间等以及一些其他信息。

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
    <!-- 规定默认地址-->
    <base href="http://www.baidu.com"></base>
    <!-- 规定默认目标-->
    <base target="_blank"></base>
    <!-- 连接样式表-->
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    <!-- 向浏览器传送信息,告诉浏览器这个文档的字符集类型-->
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
    <!-- 文档作者-->
    <meta name="author" content="LiXianLi">
    <!--修订时间-->
    <meta name="revised" content="panda,12/10/2015">
</head >
</html>

5、<script>标签用于定义客户端脚本

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
    <!-- 规定默认地址-->
    <base href="http://www.baidu.com"></base>
    <!-- 规定默认目标-->
    <base target="_blank"></base>
    <!-- 连接样式表-->
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    <!-- 向浏览器传送信息,告诉浏览器这个文档的字符集类型-->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <!-- 文档作者-->
    <meta name="author" content="LiXianLi">
    <!--修订时间-->
    <meta name="revised" content="panda,12/10/2015">
</head >
<body>
    <script type="text/javascript">
        document.write("hello world")
    </script>
</body>
</html>

6、<style>标签用于为HTML文档定义样式信息

<!DOCTYPE html>
<html>
<head>
    <title> This is my HTML</title>
    <!-- 规定默认地址-->
    <base href="http://www.baidu.com"></base>
    <!-- 规定默认目标-->
    <base target="_blank"></base>
    <!-- 连接样式表-->
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    <!-- 向浏览器传送信息,告诉浏览器这个文档的字符集类型-->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <!-- 文档作者-->
    <meta name="author" content="LiXianLi">
    <!--修订时间-->
    <meta name="revised" content="panda,12/10/2015">
    <!-- 定义样式信息-->
    <style type="text/css">
    body {background-color: green}
    p {color: blue}
    </style>
</head >
<body>
    <script type="text/javascript">
        document.write("hello world")
    </script>
    <p>测试脚本</p>
</body>
</html>

以上就是HTML中head元素常用标签介绍的详细内容,更多请关注光雨网络其它相关文章!

本站文章均为光雨网络深圳网站建设摘自权威资料,书籍,杂志或原创文章,如有版权纠纷或者违规问题,请即刻联系我们删除,我们欢迎您分享到社交网站,引用和转载,我们谢绝直接复制和抄袭!感谢您...