CSS学习————背景属性(4)

一、颜色背景:

1、backgound-color:纯颜色

 

.box:nth-child(1) {
	background-color: darkred;
}
.box:nth-child(2) {
	background-color: black;
	opacity: .2;
}
.box:nth-child(3) {
	background-color: rgb(0, 255, 0);
}
.box:nth-child(4) {
	background-color: rgb(0, 255, 0, .1);
}
.box:nth-child(5) {
	background-color: hsl(270, 80%, 50%);
}
.box:nth-child(6) {
	background-color: hsla(270, 80%, 50%,.5);
}
.box:nth-child(7) {
	background-color: #FF00FF;
}

2、渐变颜色:

2-1:线性渐变

background-image: linear-gradient(direction, color-stop1, color-stop2, ...);

重复:repeating-linear-gradient() 函数

 

2-2:径向渐变

background-image: radial-gradient(shape size at position, start-color, ..., last-color);

1、shape:circle | ellipse(默认值),
2、size 定义渐变的大小,可能值有:
farthest-corner(默认):指定径向渐变的半径长度为从圆心到离圆心最远的角;
closest-side:指定径向渐变的半径长度为从圆心到离圆心最近的边;
closest-corner:指定径向渐变的半径长度为从圆心到离圆心最近的角;
farthest-side:指定径向渐变的半径长度为从圆心到离圆心最远的边;
3、position :top | bottom | center(默认值)

二、图片背景

1、background-image:

2、background-repeat:repeat-x | repeat-y | no-repaet | repeat

3、background-size:20px 30px  | 10% 20 %| cover | contain 

百分比和具体像素,设置宽/高,如果高不设置默认auto

4、background-position:

 

5、background-attachment:

 

4、background-origin:border-box | padding-box | content-box

设置了poisition 以上属性无效

5、规定背景的绘制区域: background-clip:border-box | padding-box | content-box

 

<!DOCTYPE html>
<html>
	<head>
		<style>
			:root {
				background-color: gray;
			}

			.box {
				float: left;
				margin-left: 10px;
				height: 100px;
				width: 200px;
				color: #fff;
				border: 20px solid rgba(0, 0, 0, .5);
				padding: 20px;
				background-color: green;
			}

			.box:nth-child(1) {
				background-clip: border-box;
			}

			.box:nth-child(2) {
				background-clip: padding-box;
			}

			.box:nth-child(3) {
				background-clip: content-box;
			}
		</style>
	</head>
	<body>
		<div class="box">设置border-box设置border-box设置border-box设置border-box设置border-box</div>
		<div class="box">设置padding-box设置padding-box设置padding-box设置padding-box</div>
		<div class="box">设置content-box设置content-box设置content-box</div>
	</body>
</html>

6、background-blend-mode:

 

 

.box:nth-child(2) {
	background-image: url("img/bg_flower.gif"), url("./img/img_bg.jpg");
	background-repeat: no-repeat;
	background-size: 40%, 100%;
	background-origin: content-box, padding-box;
	background-blend-mode: overlay;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CSS(层叠样式表)是一种用于描述网页样式的标记语言,通过控制网页元素的外观和布局来美化页面。背景样式在 CSS 中扮演了重要角色,可以通过设置背景颜色、背景图片、背景大小、背景重复等属性来改变元素的背景效果。以下是一些常用的背景样式属性: 1. 背景颜色(background-color):用于设置元素的背景色,可以使用命名颜色或者十六进制颜色值。 示例: ```css div { background-color: red; } ``` 2. 背景图片(background-image):用于设置元素的背景图片,可以使用图片的 URL 来指定。 示例: ```css div { background-image: url("image.jpg"); } ``` 3. 背景大小(background-size):用于设置背景图片的尺寸大小,可以使用关键字(如 `cover`、`contain`)或具体数值(如像素、百分比)来指定。 示例: ```css div { background-size: cover; } ``` 4. 背景重复(background-repeat):用于设置背景图片的重复方式,可以是水平重复、垂直重复或者不重复。 示例: ```css div { background-repeat: repeat-x; } ``` 5. 背景定位(background-position):用于设置背景图片的起始位置,可以使用关键字(如 `top`、`center`、`bottom`)或具体数值(如像素、百分比)来指定。 示例: ```css div { background-position: center; } ``` 以上是一些常用的背景样式属性,通过灵活运用它们,可以实现丰富多样的背景效果。希望对你有所帮助!如需了解更多,请参考相关的 CSS 教程或文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值