color
属性可设置文本的颜色。那么如何给元素设置背景色呢?background-color
来设置元素的背景色:
<div style="background-color:red">我的背景是红色</div>
background-color
的值与color
一样,都是“颜色”。
<div style="background-color:red">
我的背景是红色
<div>我没有设置背景色</div>
<div style="background-color:#000000">我的背景是黑色</div>
<div style="background-color:rgb(0,0,255)">我的背景是蓝色</div>
</div>
<div>
是没有背景色的,就相当于是透明的一样。当不设置背景色时,看到的是它的父元素的背景色。