Correct use of <base> tag in HTML

HTML <base> tag

1. Definition: The <base> tag is the base URL tag in the HTML language and is a single tag.

2. Function: Specify the default URL and default target of all links on the page .

E.g:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>base</title>
    <meta charset="UTF-8">
    <base href="http://www.w3cschool.cn" target="_blank">
</head>
<body>
<p>img标签里的src的绝对路径是http://www.w3cschool.cn/statics/images/course/planets.gif</p>
<img src="/statics/images/course/planets.gif" width="145" height="126" alt="Planets">
</body>
</html>

Note: base specifies the default URL for all links on the page , yes all!  It includes all URLs such as src, href, etc.

          The link used will be spliced ​​with the href link in the base.

For example, if the css file cannot be found:

<!DOCTYPE html>
<html lang="en">
<head>
<title>base</title> 
 <meta charset="UTF-8">
<base href="http://www.w3cschool.cn" target="_blank"> 
<link rel="stylesheet" type="text/css" href="CSS/first.css" > <!--链接外部资源-->
</head>
<body>
<p> If the external style sheet wants to refer to a file in a directory other than the base link, then the style sheet will not be found. </p> 
</ body > 
</ html >

 in short:

     The base tag has the following rules

  1. The <base> tag must be inside the <head> element.
  2. In a document, at most one <base> tag can be used. 
  3. After using the link of the <base> tag, other links must be inside the link of the <base> tag, otherwise it will not be found.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325330382&siteId=291194637