1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
---
title: Alternative style sheets
slug: Web/CSS/Alternative_style_sheets
translation_of: Web/CSS/Alternative_style_sheets
---
<div>{{cssref}}</div>
<p>Specifying <strong>alternative style sheets</strong> in a web page provides a way for users to see multiple versions of a page, based on their needs or preferences.</p>
<p>在网页中指定可替代样式表允许用户为网页选择他们喜欢的样式。</p>
<p>Firefox lets the user select the stylesheet using the <em>View > Page Style</em> submenu. Internet Explorer also supports this feature (beginning with IE 8), also accessed from <em>View > Page Style</em>. Chrome requires an extension to use the feature (as of version 48). The web page can also provide its own user interface to let the user switch styles.</p>
<p>Firefox允许用户通过菜单栏中 查看 > 页面样式 选择样式表。Internet Explorer也支持这一功能(从IE8开始)(菜单栏 查看 > 页面样式)。网页也可提供自己的用户界面让用户</p>
<p>在Firefox和Internet Explorer(从IE8(6?)开始)中,用户可以通过菜单栏中的 查看 > 页面样式 来选择网页的样式。网页也可以提供选择样式的界面。</p>
<h2 id="An_example_specifying_the_alternative_stylesheets">An example: specifying the alternative stylesheets</h2>
<h2 id="示例:提供可替代样式表">示例:提供可替代样式表</h2>
<p>The alternate stylesheets are commonly specified using a {{HTMLElement("link")}} element with <code>rel="alternate stylesheet"</code> and <code>title="..."</code> attributes. For example:</p>
<p>一般使用<{{HTMLElement("link")}}>指定可替换样式表。在这个标签中指定<code>rel="alternate stylesheet"</code> 属性和 <code>title="..."</code>属性</p>
<pre class="brush: html"><link href="reset.css" rel="stylesheet" type="text/css">
<link href="default.css" rel="stylesheet" type="text/css" title="Default Style">
<link href="fancy.css" rel="alternate stylesheet" type="text/css" title="Fancy">
<link href="basic.css" rel="alternate stylesheet" type="text/css" title="Basic">
</pre>
<p>In this example, the styles "Default Style", "Fancy", and "Basic" will be listed in the <em>Page Style</em> submenu, with "Default Style" pre-selected. When the user selects a different style, the page will immediately be re-rendered using that style sheet.</p>
<p>在此例中,“页面样式”菜单中会出现“Default Style”、“Fancy”和“Basic”的选项。“Default Style”默认选中。如果用户选择一个不同的样式,浏览器就使用用户选择的样式。</p>
<p>No matter what style is selected, the rules from the reset.css stylesheet will always be applied.</p>
<p>无论用户选择何种样式, reset.css 总会被应用。</p>
<h3 id="尝试">尝试</h3>
<p><a href="/samples/cssref/altstyles/index.html">Click here</a> for a working example you can try out.</p>
<p><a href="https://wiki.developer.mozilla.org/samples/cssref/altstyles/index.html">点击此处</a>进入示例。</p>
<h2 id="细节">细节</h2>
<p>网页中的样式表分为三类:</p>
<p>Any stylesheet in a document falls into one of the following categories:</p>
<ul>
<li><strong>Persistent</strong> (no <code>rel="alternate"</code>, no <code>title=""</code>): always applies to the document.</li>
<li><strong>Preferred</strong> (no <code>rel="alternate"</code>, with <code>title="..."</code> specified): applied by default, but {{domxref("StyleSheet.disabled", "disabled", "", 1)}} if an alternate stylesheet is selected. <strong>There can only be one preferred stylesheet</strong>, so providing stylesheets with different title attributes will cause some of them to be ignored. See <a href="/en-US/docs/Correctly_Using_Titles_With_External_Stylesheets">Correctly Using Titles With External Stylesheets</a> for a more detailed discussion.</li>
<li><strong>Alternate</strong> (<code>rel="alternate stylesheet"</code>, <code>title="..."</code> must be specified): disabled by default, can be selected.</li>
</ul>
<p>When style sheets are referenced with a <code>title</code> attribute on the {{HTMLElement("link", "<link rel=\"stylesheet\">")}} or {{HTMLElement("style")}} element, the title becomes one of the choices offered to the user. Style sheets linked with the same <code>title</code> are part of the same choice. Style sheets linked without a <code>title</code> attribute are always applied.</p>
<p>Use <code>rel="stylesheet"</code> to link to the default style, and <code>rel="alternate stylesheet"</code> to link to alternative style sheets. This tells the browser which style sheet title should be selected by default, and makes that default selection apply in browsers that do not support alternate style sheets.</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', '#rel-alternate', 'link type "alternate"')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', '#link-type-stylesheet', 'link type "stylesheet"')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', '#attr-style-title', 'the "title" attribute for the style element')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', '#attr-meta-http-equiv-default-style', 'meta http-equiv="default-style")')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('CSSOM', '#css-style-sheet-collections', 'CSS Style Sheet Collections')}}</td>
<td>{{Spec2('CSSOM')}}</td>
<td>The CSS OM specification defines the concepts of the <strong>style sheet set name</strong>, its <strong>disabled flag</strong>, and the <strong>preferred CSS style sheet set name</strong>.<br>
It defines how these are determined, and lets the HTML specification define the HTML-specific behaviors by requiring it to define when to <strong><dfn>create a CSS style sheet</dfn></strong>.</td>
</tr>
<tr>
<td>{{SpecName("HTML4.01", "present/styles.html#h-14.3", "Alternative style sheets")}}</td>
<td>{{Spec2("HTML4.01")}}</td>
<td>Earlier, the HTML specification itself defined the concept of preferred and alternate stylesheets.</td>
</tr>
</tbody>
</table>
<p>{{Compat("html.elements.link.rel.alternate_stylesheet")}}</p>
|