aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/css/background-color/index.html
blob: 32662bbb749cfab3e3dab3a7c0bd89f95069d74d (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
---
title: background-color
slug: Web/CSS/background-color
translation_of: Web/CSS/background-color
---
<div>{{CSSRef}}</div>

<p><strong><code>background-color</code></strong> <a href="/en/CSS" title="CSS">CSS</a> property 是用來設定HTML元素的背景顏色,值可以是顏色亦可以是特定關鍵字-- <code>transparent</code>.</p>

<h2 id="語法">語法</h2>

<pre class="brush: css">background-color: red;
background-color: rgb(255, 255, 128);
background-color: hsla(50, 33%, 25%, 0.75);
background-color: currentColor;
background-color: transparent;
background-color: #bbff00;

background-color: inherit;
</pre>

<h3 id="參數">參數</h3>

<dl>
 <dt><code>&lt;color&gt;</code></dt>
 <dd>一個 CSS {{cssxref("&lt;color&gt;")}} 用來表示一致的背景顏色。即便設定了一個或多個 {{cssxref("background-image")}} ,背景渲染上依舊會渲染這顏色,若是圖片並非不透明圖,在透明區域就能看見。在 CSS 中, <code>transparent</code> 是一種顏色</dd>
</dl>

<h3 id="正式語法">正式語法</h3>

{{csssyntax}}

<h2 id="範例">範例</h2>

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

<pre class="brush: html">&lt;div class="exampleone"&gt;
 Lorem ipsum dolor sit amet, consectetuer
&lt;/div&gt;

&lt;div class="exampletwo"&gt;
  Lorem ipsum dolor sit amet, consectetuer
&lt;/div&gt;

&lt;div class="examplethree"&gt;
  Lorem ipsum dolor sit amet, consectetuer
&lt;/div&gt;</pre>

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

<pre class="brush: css; highlight:[2,7,12,17];">.exampleone {
  background-color: teal;
  color: white;
}

.exampletwo {
  background-color: rgb(153,102,153);
  color: rgb(255,255,204);
}

.examplethree {
  background-color: #777799;
  color: #FFFFFF;
}
</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample("範例","200","150")}}</p>

<h2 id="規格定義">規格定義</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', '#background-color', 'background-color')}}</td>
   <td>{{Spec2('CSS3 Backgrounds')}}</td>
   <td>技術上來說,移除了 <code>transparent</code> 關鍵字,但實際上並未發生任何改變,因為它被列入至正式的 {{cssxref("&lt;color&gt;")}}</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'colors.html#propdef-background-color', 'background-color')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>無變動</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#background-color', 'background-color')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>原始定義。</td>
  </tr>
 </tbody>
</table>

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

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("css.properties.background-color")}}</p>
<h2 id="延伸閱讀">延伸閱讀</h2>

<ul>
 <li>
  <p><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">複數背景</a></p>
 </li>
</ul>