--- title: background-color slug: Web/CSS/background-color translation_of: Web/CSS/background-color ---
background-color
CSS property 是用來設定HTML元素的背景顏色,值可以是顏色亦可以是特定關鍵字-- transparent
.
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;
<color>
transparent
是一種顏色<div class="exampleone"> Lorem ipsum dolor sit amet, consectetuer </div> <div class="exampletwo"> Lorem ipsum dolor sit amet, consectetuer </div> <div class="examplethree"> Lorem ipsum dolor sit amet, consectetuer </div>
.exampleone { background-color: teal; color: white; } .exampletwo { background-color: rgb(153,102,153); color: rgb(255,255,204); } .examplethree { background-color: #777799; color: #FFFFFF; }
{{EmbedLiveSample("範例","200","150")}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Backgrounds', '#background-color', 'background-color')}} | {{Spec2('CSS3 Backgrounds')}} | 技術上來說,移除了 transparent 關鍵字,但實際上並未發生任何改變,因為它被列入至正式的 {{cssxref("<color>")}} |
{{SpecName('CSS2.1', 'colors.html#propdef-background-color', 'background-color')}} | {{Spec2('CSS2.1')}} | 無變動 |
{{SpecName('CSS1', '#background-color', 'background-color')}} | {{Spec2('CSS1')}} | 原始定義。 |
{{cssinfo}}
{{Compat("css.properties.background-color")}}