本节介绍css的背景属性以及应用效果css常用的背景属性背景应用css3新增背景属性css常用背景属性css中的背景是由background属性来设置背景的,它是一个综合属性,可以拆分为单一的属性背景
顺晟科技
2022-09-14 11:05:52
158
背景颜色 | background-color (Backgrounds & Borders) - CSS 中文开发手册
CSS属性中的background-color会设置元素的背景色, 属性的值为颜色值或关键字"transparent"二者选其一
/* Keyword values */ background-color: red; /* Hexadecimal value */ background-color: #bbff00; /* Hexadecimal value with alpha channel */ background-color: #11ffee00; /* 00 - fully transparent */ background-color: #11ffeeff; /* ff - fully opaque */ /* RGB value */ background-color: rgb(255, 255, 128); /* RGBA value or RGB with alpha channel */ background-color: rgba(117, 190, 218, 0.0); /* 0.0 - fully transparent */ background-color: rgba(117, 190, 218, 0.5); /* 0.5 - semi-transparent */ background-color: rgba(117, 190, 218, 1.0); /* 1.0 - fully opaque */ /* HSLA value */ background-color: hsla(50, 33%, 25%, 0.75); /* Special keyword values */ background-color: currentcolor; background-color: transparent; /* Global values */ background-color: inherit; background-color: initial; background-color: unset;
初始值 | transparent |
---|
background-color属性被指定为单个<color>值。
<color>是<color>描述背景的统一颜色的CSS 。即使background-image定义了一个或几个,如果图像不透明,透明度也会影响渲染效果。在CSS中,transparent是一种颜色。
<color>where <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color> where <rgb()> = rgb( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <rgba()> = rgba( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <hsl()> = hsl( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) <hsla()> = hsla( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) where <alpha-value> = <number> | <percentage> <hue> = <number> | <angle>
<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; }
Specification | Status | Comment |
---|
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|
在Internet Explorer 8和9中,存在一个错误,即计算background-color的transparent会使得click事件不会被重叠元素触发
CSS 中文开发手册07
2022-10
20
2022-09
15
2022-09
15
2022-09
15
2022-09
14
2022-09