aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/css/css_positioning/understanding_z_index/adding_z-index/index.html
blob: 4b3dca2db00f015b5a8c1cd899531f74872f0062 (plain)
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
156
157
158
---
title: Using z-index
slug: Web/CSS/CSS_Positioning/Understanding_z_index/Adding_z-index
translation_of: Web/CSS/CSS_Positioning/Understanding_z_index/Adding_z-index
original_slug: Web/Guide/CSS/Understanding_z_index/Adding_z-index
---
<div>{{cssref}}</div>

<p>The first part of this article, <a href="/en/CSS/Understanding_z-index/Stacking_without_z-index" title="en/CSS/Understanding_z-index/Stacking_without_z-index">Stacking without the z-index property</a>, explains how stacking is arranged by default. If you want to create a custom stacking order, you can use the {{cssxref("z-index")}} property on a <a href="/en-US/docs/Web/CSS/position#Types_of_positioning">positioned</a> element.</p>

<p>Свойство <code>z-index</code> может иметь значение в целых числах (положительные, ноль, или отрицательные), что представляет собой позицию элемента вдоль оси z. Если вы не знакомы с<strong> </strong>осью<strong> </strong>z, представьте себе страницу как стопку слоёв, имеющих собственное порядковое число. Слои представлены в числовом порядке, with larger numbers above smaller numbers.</p>

<ul>
 <li>bottom layer<em> (farthest from the observer)</em></li>
 <li>...</li>
 <li>Layer -3</li>
 <li>Layer -2</li>
 <li>Layer -1</li>
 <li>Layer 0 <em>(default rendering layer)</em></li>
 <li>Layer 1</li>
 <li>Layer 2</li>
 <li>Layer 3</li>
 <li>...</li>
 <li>top layer<em> (closest to the observer)</em></li>
</ul>

<div class="note">
<p><strong>Notes:</strong></p>

<ul>
 <li>When no <code>z-index</code> property is specified, elements are rendered on the default rendering layer 0 (zero).</li>
 <li>If several elements share the same <code>z-index</code> value (i.e., they are placed on the same layer), stacking rules explained in the section <a href="/en/CSS/Understanding_z-index/Stacking_without_z-index" title="Stacking without z-index">Stacking without z-index</a> apply.</li>
</ul>
</div>

<p>In the following example, the layers' stacking order is rearranged using <code>z-index</code>. The <code>z-index</code> of element #5 has no effect since it is not a positioned element.</p>

<p>{{EmbedLiveSample("Source_code_for_the_example", 600, 400)}}</p>

<h2 id="Source_code_for_the_example"><strong>Source code for the example</strong></h2>

<h3 id="HTML"><strong>HTML</strong></h3>

<pre class="brush: html">&lt;div id="abs1"&gt;
  &lt;b&gt;DIV #1&lt;/b&gt;
  &lt;br /&gt;position: absolute;
  &lt;br /&gt;z-index: 5;
&lt;/div&gt;

&lt;div id="rel1"&gt;
  &lt;b&gt;DIV #2&lt;/b&gt;
  &lt;br /&gt;position: relative;
  &lt;br /&gt;z-index: 3;
&lt;/div&gt;

&lt;div id="rel2"&gt;
  &lt;b&gt;DIV #3&lt;/b&gt;
  &lt;br /&gt;position: relative;
  &lt;br /&gt;z-index: 2;
&lt;/div&gt;

&lt;div id="abs2"&gt;
  &lt;b&gt;DIV #4&lt;/b&gt;
  &lt;br /&gt;position: absolute;
  &lt;br /&gt;z-index: 1;
&lt;/div&gt;

&lt;div id="sta1"&gt;
  &lt;b&gt;DIV #5&lt;/b&gt;
  &lt;br /&gt;no positioning
  &lt;br /&gt;z-index: 8;
&lt;/div&gt;
</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">div {
  padding: 10px;
  opacity: 0.7;
  text-align: center;
}

b {
  font-family: sans-serif;
}

#abs1 {
  z-index: 5;
  position: absolute;
  width: 150px;
  height: 350px;
  top: 10px;
  left: 10px;
  border: 1px dashed #900;
  background-color: #fdd;
}

#rel1 {
  z-index: 3;
  height: 100px;
  position: relative;
  top: 30px;
  border: 1px dashed #696;
  background-color: #cfc;
  margin: 0px 50px 0px 50px;
}

#rel2 {
  z-index: 2;
  height: 100px;
  position: relative;
  top: 15px;
  left: 20px;
  border: 1px dashed #696;
  background-color: #cfc;
  margin: 0px 50px 0px 50px;
}

#abs2 {
  z-index: 1;
  position: absolute;
  width: 150px;
  height: 350px;
  top: 10px;
  right: 10px;
  border: 1px dashed #900;
  background-color: #fdd;
}

#sta1 {
  z-index: 8;
  height: 70px;
  border: 1px dashed #996;
  background-color: #ffc;
  margin: 0px 50px 0px 50px;
}
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en/CSS/Understanding_z-index/Stacking_without_z-index" title="en/CSS/Understanding_z-index/Stacking_without_z-index">Stacking without the z-index property</a>: The stacking rules that apply when <code>z-index</code> is not used.</li>
 <li><a href="/en/CSS/Understanding_z-index/Stacking_and_float" title="en/CSS/Understanding_z-index/Stacking_and_float">Stacking with floated blocks</a>: How floating elements are handled with stacking.</li>
 <li><a href="/en/CSS/Understanding_z-index/The_stacking_context" title="en/CSS/Understanding_z-index/The_stacking_context">The stacking context</a>: Notes on the stacking context.</li>
 <li><a href="/en/CSS/Understanding_z-index/Stacking_context_example_1" title="en/CSS/Understanding_z-index/Stacking_context_example_1">Stacking context example 1</a>: 2-level HTML hierarchy, z-index on the last level</li>
 <li><a href="/en/CSS/Understanding_z-index/Stacking_context_example_2" title="en/CSS/Understanding_z-index/Stacking_context_example_2">Stacking context example 2</a>: 2-level HTML hierarchy, z-index on all levels</li>
 <li><a href="/en/CSS/Understanding_z-index/Stacking_context_example_3" title="en/CSS/Understanding_z-index/Stacking_context_example_3">Stacking context example 3</a>: 3-level HTML hierarchy, z-index on the second level</li>
</ul>

<div class="originaldocinfo">
<h2 id="Original_Document_Information">Original Document Information</h2>

<ul>
 <li>Author(s): Paolo Lombardi</li>
 <li>This article is the English translation of an article I wrote in Italian for <a class="external" href="http://www.yappy.it">YappY</a>. I grant the right to share all the content under the <a class="external" href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.</li>
 <li>Last Updated Date: November 3, 2014</li>
</ul>
</div>