Skip to main content

背景

background-color#

默认值是 transparent 就是透明的意思,所以我们在消除一个bgc的时候就设置其值为transparent

因为是颜色,所以和前面讲的颜色表示3种方法一样

背景图片#

背景图片的优势在于,它非常的便于调整位置,比使用img更灵活

基本用法

#img1{    width: 100%;    height: 300px;    background-image: url("assets/img/wow.jpg") ;}

url写图片地址,网络本地都可以

默认值none

background-repeat#

默认值是repeat,就是平铺

还有no-repeat repeat-x repeat-y 看字面意思就懂了

background-position#

图片位置两个参数,x y 可以是方位名词,px,

background-position: center center; background-position: 30px 30px;

background-attachment背景滚动#

默认值:scroll 背景随着块一起滚动,可以改成fixed,画面固定

复合写法#

   background: black url("assets/img/wow.jpg") no-repeat fixed center;

很简单一行代码解决,没有顺序要求

背景渐变#

linear-gradient#

HTML 元素的背景色并不局限于单色。 CSS 还为我们提供了颜色渐变。 可通过 background 里的 linear-gradient() 实现线性渐变, 以下是它的语法:

background: linear-gradient(gradient_direction, color 1, color 2, color 3, ...);

第一个参数指定了颜色过渡的方向——它的值是角度,90deg 表示垂直渐变(从左到右),45deg 表示沿对角线渐变(从左下方到右上方)。 其他参数指定了渐变颜色的顺序:

例如:

background: linear-gradient(90deg, red, yellow, rgb(204, 204, 255));

repeating-linear-gradient#

有待研究下