aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/css/css_positioning/understanding_z_index/adding_z-index/index.html
blob: 9621937b5ffbcba867d47c54c083ddd697f2a408 (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
---
title: 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
---
<p>« <a href="/ko/CSS" title="CSS">CSS</a> « <a href="/ko/CSS/Understanding_z-index" title="Understanding CSS z-index"><span class="title">CSS z-index 이해하기</span></a></p>
<h3 id="cssxrefz-index_적용">{{ cssxref("z-index") }} 적용</h3>
<p>처음 예제에서(<a href="/ko/CSS/Understanding_z-index/Stacking_without_z-index" title="ko/CSS/Understanding_z-index/Stacking_without_z-index">z-index가 없는 경우의 쌓임</a>) 엘리먼트들이 기본적으로 어떻게 쌓이는지 설명했다. 만약 다른 쌓임 순서를 적용하고 싶다면 먼저 엘리먼트에 {{ cssxref("position") }} 속성을 지정하고 {{ cssxref("z-index") }} 속성을 지정해야한다. </p>
<p>z-index 속성은 하나의 정수 값을 가질 수 있다(양수, 음수 모두 가능하다). 이 값은 해당 엘리먼트의 z축 상의 위치를 나타낸다. 만약 당신이 z축에 익숙하지 않다면 여러 레이어가 쌓여있는 페이지를 상상해보라. 각 레이어는 번호가 붙어있고 높은 번호를 가진 레이어는 낮은 번호를 가진 레이어 위에 렌더링된다. </p>
<p><strong>다시한번 경고!</strong> z-index는 <a href="/en/CSS/position" title="position">position</a> 속성이 설정된 엘리먼트에 대해서만 의미를 갖는다.</p>
<ul>
  <li><em>가장 아래(사용자로부터 가장 멀다)</em></li>
  <li>...</li>
  <li>Layer -3</li>
  <li>Layer -2</li>
  <li>Layer -1</li>
  <li>Layer 0 <em>기본 렌더링 레이어</em></li>
  <li>Layer 1</li>
  <li>Layer 2</li>
  <li>Layer 3</li>
  <li>...</li>
  <li><em>가장 위(사용자로부터 가장 가깝다)</em></li>
</ul>
<div class="note">
  <p><strong>노트:</strong></p>
  <ul>
    <li>z-index 속성을 지정하지 않으면 엘리먼트는 기본 렌더링 레이어(레이어 0)에 렌더링된다. </li>
    <li>만약 몇개의 엘리먼트들이 같은 z-index 속성 값을 가지면 (엘리먼트들이 같은 레이어에 위치한다) <a href="/ko/CSS/Understanding_z-index/Stacking_without_z-index" title="Stacking without z-index">z-index가 없는 경우의 쌓임</a> 쌓임 규칙을 적용한다.</li>
  </ul>
</div>
<p>다음 예제에서는 레이어들의 쌓임 순서가 z-index를 이용하여 바뀌어있다. DIV#5는 position 속성이 지정되지 않았으므로 z-index 속성 값은 쌓임 순서를 결정하는데에 아무 영향을 미치지 않는다. </p>
<p><img alt="Example of stacking rules modified using z-index" class="internal" src="/@api/deki/files/912/=Understanding_zindex_03.png"></p>
<h3 id="Example_source_code"><strong>Example source code</strong></h3>
<pre class="brush: html">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;&lt;style type="text/css"&gt;

div {
   opacity: 0.7;
   font: 12px Arial;
}

span.bold { font-weight: bold; }

#normdiv {
   z-index: 8;
   height: 70px;
   border: 1px dashed #999966;
   background-color: #ffffcc;
   margin: 0px 50px 0px 50px;
   text-align: center;
}

#reldiv1 {
   z-index: 3;
   height: 100px;
   position: relative;
   top: 30px;
   border: 1px dashed #669966;
   background-color: #ccffcc;
   margin: 0px 50px 0px 50px;
   text-align: center;
}

#reldiv2 {
   z-index: 2;
   height: 100px;
   position: relative;
   top: 15px;
   left: 20px;
   border: 1px dashed #669966;
   background-color: #ccffcc;
   margin: 0px 50px 0px 50px;
   text-align: center;
}

#absdiv1 {
   z-index: 5;
   position: absolute;
   width: 150px;
   height: 350px;
   top: 10px;
   left: 10px;
   border: 1px dashed #990000;
   background-color: #ffdddd;
   text-align: center;
}

#absdiv2 {
   z-index: 1;
   position: absolute;
   width: 150px;
   height: 350px;
   top: 10px;
   right: 10px;
   border: 1px dashed #990000;
   background-color: #ffdddd;
   text-align: center;
}

&lt;/style&gt;&lt;/head&gt;

&lt;body&gt;

&lt;br /&gt;&lt;br /&gt;

&lt;div id="absdiv1"&gt;
   &lt;br /&gt;&lt;span class="bold"&gt;DIV #1&lt;/span&gt;
   &lt;br /&gt;position: absolute;
   &lt;br /&gt;z-index: 5;
&lt;/div&gt;

&lt;div id="reldiv1"&gt;
   &lt;br /&gt;&lt;span class="bold"&gt;DIV #2&lt;/span&gt;
   &lt;br /&gt;position: relative;
   &lt;br /&gt;z-index: 3;
&lt;/div&gt;

&lt;div id="reldiv2"&gt;
   &lt;br /&gt;&lt;span class="bold"&gt;DIV #3&lt;/span&gt;
   &lt;br /&gt;position: relative;
   &lt;br /&gt;z-index: 2;
&lt;/div&gt;

&lt;div id="absdiv2"&gt;
   &lt;br /&gt;&lt;span class="bold"&gt;DIV #4&lt;/span&gt;
   &lt;br /&gt;position: absolute;
   &lt;br /&gt;z-index: 1;
&lt;/div&gt;

&lt;div id="normdiv"&gt;
   &lt;br /&gt;&lt;span class="bold"&gt;DIV #5&lt;/span&gt;
   &lt;br /&gt;no positioning
   &lt;br /&gt;z-index: 8;
&lt;/div&gt;

&lt;/body&gt;&lt;/html&gt;
</pre>
<h3 id="See_also">See also</h3>
<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 z-index</a> : Default stacking rules</li>
  <li><a href="/en/CSS/Understanding_z-index/Stacking_and_float" title="en/CSS/Understanding_z-index/Stacking_and_float">Stacking and float</a> : How floating elements are handled</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">
  <h3 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h3>
  <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 <a class="external" href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a></li>
    <li>Last Updated Date: July 9th, 2005</li>
  </ul>
</div>
<p>{{ languages( { "fr": "fr/CSS/Comprendre_z-index/Ajout_de_z-index" } ) }}</p>