Menu

[r5]: / docs / inheritance.html  Maximize  Restore  History

Download this file

155 lines (132 with data), 4.5 kB

  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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Inheritance: Switch</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link type="text/css" rel="stylesheet" title="Default Stylesheet" href="global.css" />
</head>
<body id="inheritance" class="documentation">
<div id="header">
</div>
<div id="localNav">
<h2>Switch</h2>
<ul id="extensionsNav">
<li><a href="install_mac.html">Installation (Mac)</a></li>
<li><a href="install_windows.html">Installation (Windows)</a></li>
<li><a href="variables.html">Variables</a></li>
<li><a href="constants.html">Constants</a></li>
<li><a href="includes.html">Includes</a></li>
<li><a href="comments.html">Comments</a></li>
<li><a href="ignore.html">Ignore</a>
<li><a href="auto_prepending.html">Automatic Selector Prepending</a></li>
<li><a href="inheritance.html">Inheritance</a></li>
<li><a href="copy.html">Property Duplication</a></li>
<li><a href="property_lookup.html">Property Look-ups</a></li>
</ul>
</div>
<div id="mainContent">
<h2>Inheritance: <code>@inherit</code></h2>
<p>Inhertiance allows a style rule to gain all the visual behavior of one or more style rules through selector manipulation. Selectors specified in the <code>@inherit</code> directive will match rules declared previously in the stylesheet.</p>
<div class="example">
<pre class="input"><code>.box {
border: 1px solid #f00;
padding: 10px;
margin-bottom: 5px;
font-size: 125%;
clear: both;
}
.box_like {
@inherit .box;
border-color: #000;
}</code></pre>
<pre class="output"><code>.box,
.box_like {
border: 1px solid #f00;
padding: 10px;
margin-bottom: 5px;
font-size: 125%;
clear: both;
}
.box_like {
border-color: #000;
}</code></pre>
</div>
<p>For each selector specified by a <code>@inherit</code> directive, the <em>entire</em> selector will be match <em>anywhere</em> in previous selectors. This ensures that in all cases, the inheriting rule is rendered just like the rule it inherits from in addition to any child elements.</p>
<div class="example">
<pre class="input"><code>.box {
border: 1px solid #f00;
padding: 10px;
margin-bottom: 5px;
font-size: 125%;
clear: both;
}
#body_id .box {
background-color: #ccc;
}
.box p em {
font-weight: bold;
}
#body_id .box p em {
color: red;
}
.box_like {
@inherit .box;
border-color: #000;
}</code></pre>
<pre class="output"><code>.box,
.box_like {
border: 1px solid #f00;
padding: 10px;
margin-bottom: 5px;
font-size: 125%;
clear: both;
}
#body_id .box,
#body_id .box_like {
background-color: #ccc;
}
.box p em,
.box_like p em {
font-weight: bold;
}
#body_id .box p em,
#body_id .box_like p em {
color: red;
}
.box_like {
border-color: #000;
}</code></pre>
</div>
<p><code>@inherit</code> can be declared anywhere inside a style rule. Multiple inheritance can be indicated by providing a comma-separated list of selectors, using multiple <code>@inherit</code> rules, or both. Note that subsequent <code>@inherit</code> directive do not replace previous ones!</p>
<p>To specifically address rules inside other rules (rules that use automatic selector prepending), authors must use the entire calculated selector.</p>
<div class="example">
<pre class="input"><code>.item {
color: #000;
}
.list {
.item {
border: 1px solid #fff;
}
}
.vauge_item {
@inherit .item; /* will inherit all rules with .item */
}
.specific_item {
@inherit .list .item; /* will inherit only .list .item rules */
}</code></pre>
<pre class="output"><code>.item,
.vauge_item {
color: #000;
}
.list .item,
.list .vauge_item,
.list .specific_item {
border: 1px solid #fff;
}
.list { }
.specific_item { }</code></pre>
</div>
<h3>Using <code>@inherit</code> with imported stylesheets</h3>
<p>Selectors specified in an <code>@inherit</code> directive will match and modify selectors of rules that are imported into a stylesheet (using <code>@import</code>), however, since these rules <em>will not</em> be output with the host stylesheet, the result may not be what an author intended. It's best to inherit from rules that are declared or are included (using <code>@include</code>) into the current style sheet.</p>
</body>
</html>
MongoDB Logo MongoDB