search
HomeWeb Front-endHTML Tutorialrel attribute of HTML link tag_HTML/Xhtml_web page production

The

tag defines the relationship between the current document and other documents in the web collection. The link element is an empty element and contains only attributes. This element can only exist in the head section, but it can appear any number of times. In HTML, the tag does not have a closing tag. In XHTML, the tag must be closed properly.

In addition to the standard general attributes of HTML, the link element also includes many optional attributes: charset, href, hreflang, media, rel, rev, target, title and type. Among these attributes, target is only allowed to be used in Transitional and Frameset DTDs, and the others can be used in Strict, Transitional and Frameset DTDs.

Among these attributes, the rel attribute is the core. In this article, Script House will introduce some rel attributes that we know, as well as the processing of some link elements in WordPress, which is suitable for novice friends to learn.

1. Call external style sheet

(1). Monitor style sheet

The most common use of the

link tag is to call external style sheets, such as the following:

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"stylesheet"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://paranimage.com/wp-content/themes/v5/style.css" </span><span class="attribute-name">type</span></font>=<font face="Arial"><span class="attribute-value">"text/css" </span><span class="attribute-name">media</span></font>=<font face="Arial"><span class="attribute-value">"screen" </span><span class="error"><span class="attribute-name">/</span></span></font>></code>

where href is the URL of the target document, type specifies the MIME type of the target URL, and media specifies the device on which the document will be displayed. .

(2). Printing device style sheet

The following style sheet call of webdesignerwall specifies the CSS style when the document is displayed on the printing device:

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"stylesheet"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://www.webdesignerwall.com/wp-content/themes/wdw/print.css" </span><span class="attribute-name">type</span></font>=<font face="Arial"><span class="attribute-value">"text/css" </span><span style="COLOR: #ff9900"><span class="attribute-name">media</span>=</span><span class="attribute-value"><span style="COLOR: #ff9900">"print"</span> </span><span class="error"><span class="attribute-name">/</span></span></font>></code>

(3). Replaceable style sheet

You may also see style sheet calling code such as the following in some web pages:

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"alertnate stylesheet"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://paranimage.com/wp-content/themes/v5/red.css" </span><span class="attribute-name">type</span></font>=<font face="Arial"><span class="attribute-value">"text/css" </span><span class="attribute-name">media</span></font>=<font face="Arial"><span class="attribute-value">"screen" </span><span class="error"><span class="attribute-name">/</span></span></font>></code>

This code defines an replaceable style sheet, which is used at the same time as the first link element. The first one defines the preferred style, and this one allows the user to choose the replacement style. However, this replacement operation requires browser support, but many browsers such as IE do not support it.

So web pages that use replacement styles generally use some style sheet switching JS to allow users to freely switch interface styles. Everyone should have seen this. Some websites will define multiple colors for web pages. If WordPress users are interested, they can download Small Potato’s WPDesigner7 to try out this WordPress theme (or check out the DEMO), which uses a simple JS And multiple replaceable styles, allowing users to change the color of the web page. For a slightly more advanced version, you can also use JS to make the style change over time. For example, it will be displayed in bright color during the day and dark color at night.

Note: Specify media="all" for the preferred style, and then add a print style, which will be more consistent with Web standards (although for ordinary websites, few people will want to print your Web page). The Parlan image does not have a defined print style. I will take the time to do it later rel attribute of HTML link tag_HTML/Xhtml_web page production

Note: Whether to use replaceable styles is a question worth considering. If you only change the color scheme but the overall tone remains the same, that's acceptable. But some friends, such as WordPress users, will enable multiple completely different styles of themes, and then use plug-ins to allow users to freely change. This may seem cool, but my advice is don't do it. Regardless of whether it affects SEO, it will make people lack a fixed image of your website.

2. Define website favorites icon

For detailed information about favicon/favorite icon, you can view Baidu Encyclopedia (1, 2), and use the following code to call it.

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"shortcut icon"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://paranimage.com/wp-content/themes/v5/images/favicon.ico" </span><span class="attribute-name">type</span></font>=<font face="Arial"><span class="attribute-value">"images/x-icon"</span><span class="error"><span class="attribute-name">/</span></span></font>>
<span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"icon"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://paranimage.com/wp-content/themes/v5/images/favicon.png" </span><span class="attribute-name">type</span></font>=<font face="Arial"><span class="attribute-value">"images/png"</span><span class="error"><span class="attribute-name">/</span></span></font>></code>

I am still a little confused about this call. The result of my experiment is:

  • IE only supports favicon in ico format;
  • The rel attribute must contain shortcut to be displayed in IE;
  • I always have problems when making icos in transparent format. There is always a black background. Even if it is not black in IE, it becomes black again in Chrome.
  • So, make a transparent ico and a transparent png, the first paragraph can be called by IE browser, and the second paragraph can be called by other browsers;

Note: You can also directly create a favicon.ico file without using this link element and place it in the root directory of the website.

Shunding Share: Add Apple Touch icon to your website

iPhone or iPod Touch devices allow users to add website links to the home screen. Use the following code to assign an Apple Touch icon to your website:

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"apple-touch-icon"</span> </span><span class="attribute-name">href</span>=<font face="Arial"><span class="attribute-value">"http://paranimage.com/wp-content/themes/v5/images/apple-touch-icon.png" </span><span class="error"><span class="attribute-name">/</span></span></font>></code>

The size of the icon is 57*57 in PNG format. If not, it will be automatically scaled. And if I am not mistaken, it does not have to be made into iPhone-style beautiful rounded corners. The iPhone will automatically press it. The style makes the icon rounded and gradient, such as last.fm’s apple touch icon.

apple touch icon <link>标签的rel属性全解析

对于国内的用户来说,使用iPhone的人还不多,即使很多,会把你网站放到主屏?那恐怕不是我们这些一般的小网站能够做到的。不过好玩嘛,我还是为我的网站制作了一个并添加了这个link元素。

3. WordPress中的link元素

(1). RSS地址和Pingback地址

下面是WordPress默认主题对RSS2地址,Atom地址和Pingback地址的定义。具体原理俺觉得很深奥很复杂,就不研究了。反正你的博客需要它,Atom好像不要也可以?

<code><link style="COLOR: #ff9900">
<font face="Arial">rel="alternate" type="application/rss+xml"</font> title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link style="COLOR: #ff9900">
<font face="Arial">rel="alternate" type="application/atom+xml"</font> title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
<link>
<font face="Arial">rel="pingback"</font> href="<?php bloginfo('pingback_url'); ?>" /></code>

(2). 用于远程发布的link元素

如果你的主题中有这个函数,下面这两个link元素就会出现:

<code><span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"EditURI"</span> </span><span class="attribute-name">type</span>=<font face="Arial"><span class="attribute-value">"application/rsd+xml" </span><span class="attribute-name">title</span></font>=<font face="Arial"><span class="attribute-value">"RSD" </span><span class="attribute-name">href</span></font>=<font face="Arial"><span class="attribute-value">"http://localhost/wordpress/xmlrpc.php?rsd" </span><span class="error"><span class="attribute-name">/</span></span></font>>
<span class="start-tag">link</span><span class="attribute-name"> <span style="COLOR: #ff9900">rel</span></span><span style="COLOR: #ff9900">=</span><span class="attribute-value"><span style="COLOR: #ff9900">"wlwmanifest"</span> </span><span class="attribute-name">type</span>=<font face="Arial"><span class="attribute-value">"application/wlwmanifest+xml" </span><span class="attribute-name">href</span></font>=<font face="Arial"><span class="attribute-value">"http://localhost/wordpress/wp-includes/wlwmanifest.xml" </span><span class="error"><span class="attribute-name">/</span></span></font>></code>

这两个元素主要供远程发布使用,比如你使用Windows Live Write等桌面博客编辑器来发布文章。如果你并不需要这个功能,那完全可以把这两个元素删除,删除的方法是,打开你WordPress主题的functions.php, 在最底部的 或者 ?> 标签之前,插入下面的代码:

<code>remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');</code>

注释: 你可能在想,既然是函数生成了这两个东西,把它删除不就可以了。是的,如果你预计你其它任何插件都不会需要到这个函数,那就删吧。

4. 防止重复内容的canonical属性

谷歌、雅虎和live search在今年2月左右宣布支持Link的一个新属性Canonical,主要作用是为网页指定权威链,以解决重复内容问题。

关于这个属性的详细介绍请看谷歌中文网站管理员中的指定您的URL范式

这里主要为WordPress用户推荐两个插件来实现添加此属性到你的head部份: SEO No DuplicateCanonical URL’s。用哪个随便吧。

说了是全解析,其实仅仅是说一些常用的,对大多数人来说都已经足够了,如果你还知道其它比较重要和常用的rel属性,也欢迎分享出来。

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
link和import的区别细说:分析它们有何不同?link和import的区别细说:分析它们有何不同?Jan 06, 2024 am 08:19 AM

深入解析:link与import的区别是什么?在开发网页或应用程序时,我们经常需要引入外部的CSS文件或JavaScript库来增强或定制我们的代码。在这个过程中,link和import是两种常用的方法。虽然它们的目的都是引入外部资源,但在具体的使用上存在一些区别。语法和位置:link:使用link标签将外部资源链接到HTML文件中,通常位于HTML文档的头

link标签和import有什么区别link标签和import有什么区别Aug 28, 2023 am 11:19 AM

link标签和import的区别有语法和用途、功能和特性、加载时机、兼容性和支持等。详细介绍:1、语法和用途,link标签是HTML标签,用于在HTML文档中引入外部资源,如CSS样式表、JavaScript脚本、图标等,import是ES6中的模块导入语法,用于在JavaScript文件中引入外部模块;2、功能和特性,link标签可以引入多种资源,如CSS样式表、图标等等。

import和link之间有哪些区别import和link之间有哪些区别Nov 24, 2023 pm 02:15 PM

import和link之间的区别:1、用途和语义;2、加载方式;3、兼容性;4、链接多个样式表;5、媒体类型;6、动态性;7、错误处理;8、嵌套;9、默认样式;10、兼容性考虑;11、性能考虑;12、使用场景。详细介绍:1、用途和语义,link是HTML标签,用于链接到外部的CSS文件或样式表,它通常位于HTML文档的head部分,import是CSS的一部分等等。

对比link和import:它们有哪些差异?对比link和import:它们有哪些差异?Jan 06, 2024 pm 08:23 PM

link与import之争:它们有何不同之处?在开发和编程中,我们经常需要与其他文件或模块进行交互。为了实现这种交互,链接(linking)和导入(importing)是两种常用的方式。然而,许多人可能并不清楚link和import有什么不同之处以及何时使用它们。本文将详细介绍link和import的区别,并提供代码示例。首先,我们来了解link的概念。链接

link标签与a标签的不同之处link标签与a标签的不同之处Feb 19, 2024 pm 06:16 PM

link标签和a标签是HTML中常用的两种标签,它们有着不同的作用和用法。link标签link标签主要用于在HTML文档中引入外部资源,通常用于引入外部样式表(CSS文件),也可以用于引入其他类型的文件,如图像文件、音频文件等。link标签位于标签中,通常写在其他元数据(如标签)的后面。link标签的基本语法格

link和import有什么区别link和import有什么区别Aug 25, 2023 pm 04:10 PM

link和import的区别是:1、link是一种用于在静态链接时将代码库或对象文件连接到可执行文件中的关键字,而import是一种在运行时动态加载外部模块或库的关键字;2、link的主要作用是将不同的代码模块组合成一个整体,以便在运行时一起执行,import的主要作用是在运行时引入外部模块,以便在程序中使用其功能。

react中怎么用link跳转react中怎么用link跳转Jan 06, 2023 am 10:33 AM

react中用link跳转的方式:1、通过Link跳转携带隐形参数,然后使用“this.props.location.query”拿到所传参数对象;2、通过Link跳转携带显性参数,然后使用“this.props.match.params.id”获取参数。

html中是如何引入css样式?以及link与@import的区别(代码实例)html中是如何引入css样式?以及link与@import的区别(代码实例)Sep 13, 2018 pm 03:08 PM

在前端网站的开发过程中,我们都是要用到css样式的,css样式可以有效地对页面的布局、字体、颜色、背景和其它效果实现更加精确的控制。那么这些css样式的文件或者代码是如何导入到html中的?本章就给大家带来html中是怎样导入CSS样式?以及link与@import的区别(代码实例),让大家了解css样式是如何导入的,重点描述css样式文件的导入。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software