aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/css/background-size/index.html
blob: 05c44594534ba96816c0fd77ffa6abd56c740aa1 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
---
title: background-size
slug: Web/CSS/background-size
tags:
  - CSS
  - CSS Background
  - CSS Property
  - Reference
translation_of: Web/CSS/background-size
---
<div>{{CSSRef}}</div>

<div><a href="/ko/docs/CSS">CSS</a> <strong><code>background-size</code></strong> 속성은 요소 배경 이미지의 크기를 설정합니다. 그대로 두거나, 늘리고 줄이거나, 공간에 맞출 수 있습니다.</div>

<div></div>

<div>{{EmbedInteractiveExample("pages/css/background-size.html")}}</div>



<p>배경 이미지로 덮이지 않은 공간은 {{cssxref("background-color")}} 속성으로 채워지고, 배경 이미지에서 투명하거나 반투명한 부분을 통해서도 배경색이 보입니다.</p>

<h2 id="구문">구문</h2>

<pre class="brush: css no-line-numbers">/* 키워드 값 */
background-size: cover;
background-size: contain;

/* 단일 값 구문 */
/* 이미지 너비 (높이는 'auto'가 됨) */
background-size: 50%;
background-size: 3.2em;
background-size: 12px;
background-size: auto;

/* 두 개 값 구문 */
/* 첫 번째 값: 이미지 너비, 두 번째 값: 이미지 높이 */
background-size: 50% auto;
background-size: 3em 25%;
background-size: auto 6px;
background-size: auto auto;

/* 다중 배경 */
background-size: auto, auto; /* `auto auto`와 혼동하지 말 것 */
background-size: 50%, 25%, 25%;
background-size: 6px, auto, contain;

/* 전역 값 */
background-size: inherit;
background-size: initial;
background-size: unset;
</pre>

<p> <code>background-size</code> 속성은 다음 방법 중 하나로 지정할 수 있습니다. </p>

<ul>
 <li><code><a href="#contain">contain</a></code> 또는 <code><a href="#cover">cover</a></code> 키워드 값 사용.</li>
 <li>너비 값만 사용. 높이는 자동으로 <code>{{anch("auto")}}</code>가 됩니다.</li>
 <li>너비와 높이 값을 모두 사용. 첫 번째 값은 너비로, 두 번째 값은 높이를 설정합니다. 각 값은 {{cssxref("&lt;length&gt;")}}, {{cssxref("&lt;percentage&gt;")}}, <code>{{anch("auto")}}</code>를 사용할 수 있습니다.</li>
</ul>

<p>여러 배경 이미지의 사이즈를 지정하려면 각각의 값을 쉼표로 구분하세요.</p>

<h3 id="값"></h3>

<dl>
 <dt><a id="contain" name="contain"><code>contain</code></a></dt>
 <dd>이미지가 잘리거나 찌그러지지 않는 한도 내에서 제일 크게 설정.</dd>
 <dt><a id="cover" name="cover"><code>cover</code></a></dt>
 <dd>이미지가 찌그러지지 않는 한도 내에서 제일 크게 설정. 이미지의 가로세로비가 요소와 다르다면 이미지를 세로 또는 가로방향으로 잘라내어 빈 공간이 생기지 않도록 설정합니다.</dd>
 <dt><a id="auto" name="auto"><code>auto</code></a></dt>
 <dd>배경 이미지의 원본 크기를 유지.</dd>
 <dt id="length">{{cssxref("&lt;length&gt;")}}</dt>
 <dd>원본 크기의 너비/높이를 주어진 값으로 늘리거나 줄임. 음수는 유효하지 않습니다.</dd>
 <dt id="percentage">{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>Stretches the image in the corresponding dimension to the specified percentage of the <em>background positioning area</em>. The background positioning area is determined by the value of {{cssxref("background-origin")}} (by default, the padding box). However, if the background's {{cssxref("background-attachment")}} value is <code>fixed</code>, the positioning area is instead the entire {{glossary("viewport")}}. Negative values are not allowed.</dd>
</dl>

<h3 id="원본_크기와_비율">원본 크기와 비율</h3>

<p>The computation of values depends on the image's intrinsic dimensions (width and height) and intrinsic proportions (width-to-height ratio). These attributes are as follows:</p>

<ul>
 <li>A bitmap image (such as JPG) always has intrinsic dimensions and proportions.</li>
 <li>A vector image (such as SVG) does not necessarily have intrinsic dimensions. If it has both horizontal and vertical intrinsic dimensions, it also has intrinsic proportions. If it has no dimensions or only one dimension, it may or may not have proportions.</li>
 <li>CSS {{cssxref("&lt;gradient&gt;")}}s have no intrinsic dimensions or intrinsic proportions.</li>
 <li>Background images created with the {{cssxref("element()")}} function use the intrinsic dimensions and proportions of the generating element.</li>
</ul>

<div class="note">
<p><strong>Note:</strong> The behavior of <code>&lt;gradient&gt;</code>s changed in Gecko 8.0 {{geckoRelease("8.0")}}. Before this, they were treated as images with no intrinsic dimensions, but with intrinsic proportions identical to that of the background positioning area.</p>
</div>

<div class="note">
<p><strong>Note:</strong> In Gecko, background images created using the {{cssxref("element()")}} function are currently treated as images with the dimensions of the element, or of the background positioning area if the element is SVG, with the corresponding intrinsic proportion. This is non-standard behavior.</p>
</div>

<p>Based on the intrinsic dimensions and proportions, the rendered size of the background image is computed as follows:</p>

<dl>
 <dt>If both components of <code>background-size</code> are specified and are not <code>auto</code>:</dt>
 <dd>The background image is rendered at the specified size.</dd>
 <dt>If the <code>background-size</code> is <code>contain</code> or <code>cover</code>:</dt>
 <dd>While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area.</dd>
 <dt>If the <code>background-size</code> is <code>auto</code> or <code>auto auto</code>:</dt>
 <dd>
 <ul>
  <li>If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size.</li>
  <li>If the image has no intrinsic dimensions and has no intrinsic proportions, it's rendered at the size of the background positioning area.</li>
  <li>If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if <code>contain</code> had been specified instead.</li>
  <li>If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension. The other dimension is computed using the specified dimension and the intrinsic proportions.</li>
  <li>If the image has only one intrinsic dimension but has no intrinsic proportions, it's rendered using the specified dimension and the other dimension of the background positioning area.</li>
 </ul>
 </dd>
 <dd>
 <div class="note"><strong>Note:</strong> SVG images have a <code><a href="/en-US/docs/Web/SVG/Attribute/preserveAspectRatio">preserveAspectRatio</a></code> attribute that defaults to the equivalent of <code>contain</code>. In Firefox 43, as opposed to Chrome 52, an explicit <code>background-size</code> causes <code>preserveAspectRatio</code> to be ignored.</div>
 </dd>
 <dt>If the <code>background-size</code> has one <code>auto</code> component and one non-<code>auto</code> component:</dt>
 <dd>
 <ul>
  <li>If the image has intrinsic proportions, it's stretched to the specified dimension. The unspecified dimension is computed using the specified dimension and the intrinsic proportions.</li>
  <li>If the image has no intrinsic proportions, it's stretched to the specified dimension. The unspecified dimension is computed using the image's corresponding intrinsic dimension, if there is one. If there is no such intrinsic dimension, it becomes the corresponding dimension of the background positioning area.</li>
 </ul>
 </dd>
</dl>

<div class="note">
<p><strong>Note:</strong> Background sizing for vector images that lack intrinsic dimensions or proportions is not yet fully implemented in all browsers. Be careful about relying on the behavior described above, and test in multiple browsers to be sure the results are acceptable.</p>
</div>

<h3 id="형식_구문">형식 구문</h3>

{{csssyntax}}

<h2 id="예제">예제</h2>

<p>Please see <a href="/en-US/docs/Web/CSS/CSS_Backgrounds_and_Borders/Scaling_background_images">Scaling background images</a> for examples.</p>

<h2 id="참고">참고</h2>

<p>If you use a <code>&lt;gradient&gt;</code> as the background and specify a <code>background-size</code> to go with it, it's best not to specify a size that uses a single <code>auto</code> component, or is specified using only a width value (for example, <code>background-size: 50%</code>). Rendering of <code>&lt;gradient&gt;</code>s in such cases changed in Firefox 8, and at present is generally inconsistent across browsers, which do not all implement rendering in full accordance with <a href="http://www.w3.org/TR/css3-background/#the-background-size" title="http://www.w3.org/TR/css3-background/#the-background-size">the CSS3 <code>background-size</code> specification</a> and with <a href="http://dev.w3.org/csswg/css3-images/#gradients">the CSS3 Image Values gradient specification</a>.</p>

<pre class="brush: css">.gradient-example {
  width: 50px;
  height: 100px;
  background-image: linear-gradient(blue, red);

  /* Not safe to use */
  background-size: 25px;
  background-size: 50%;
  background-size: auto 50px;
  background-size: auto 50%;

  /* Safe to use */
  background-size: 25px 50px;
  background-size: 50% 50%;
}
</pre>

<p>Note that it's particularly not recommended to use a pixel dimension and an <code>auto</code> dimension with a <code>&lt;gradient&gt;</code>, because it's impossible to replicate rendering in versions of Firefox prior to 8, and in browsers not implementing Firefox 8's rendering, without knowing the exact size of the element whose background is being specified.</p>

<h2 id="Specifications" name="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('CSS3 Backgrounds', '#the-background-size', 'background-size')}}</td>
   <td>{{Spec2('CSS3 Backgrounds')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<p>{{cssinfo}}</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">브라우저 호환성</h2>

<p>{{Compat("css.properties.background-size")}}</p>

<h2 id="같이_보기">같이 보기</h2>

<ul>
 <li><a href="/en-US/docs/CSS/Scaling_background_images" title="CSS/Scaling_background_images">Scaling background images</a></li>
 <li><a href="/en-US/docs/Web/CSS/Scaling_of_SVG_backgrounds">Scaling of SVG backgrounds</a></li>
 <li>{{cssxref("object-fit")}}</li>
</ul>