前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >css中背景属性核心

css中背景属性核心

作者头像
贵哥的编程之路
发布2020-10-28 10:35:26
4360
发布2020-10-28 10:35:26
举报
文章被收录于专栏:用户7873631的专栏

background-color

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        div
        {
        	width: 500px;
        	height: 500px;
       	}
       	.box1
       	{
       		background-color: red;
       	}
       	.box2
       	{
       		background-color: rgb(0,255,0);
       	}
       	.box3
       	{
       		background-color: rgba(0,0,255,1);
       	}
       	.box4
       	{
       		background-color: #0ff;
       	}
    </style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</body>
</html>

核心:rgba代表红绿蓝透明,混合在一起的颜色

background-image

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		div
		{
			width: 500px;
			height: 500px;
		}
		.box1
		{
			background-image: url(./1.jpg);
		}
	</style>
</head>
<body>
<div class="box1"></div>
</body>
</html>

核心:默认背景图片是重复平铺的。直到宽高都500px。

background-repeat

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<title>
		
	</title>
	<style type="text/css">
		 div{
            width: 500px;
            height: 500px;
        }
        .box1
        {background-image: url(./1.jpg);
        background-repeat: repeat-y;
        }
        
	</style>
</head>
<body>
<div class="box1"></div>

</body>
</html>

核心:往xy轴平铺到规定的盒子的范围内.

background-position

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
div{
	width: 500px;
height: 500px;
	
}
.box1
{
	background-image: url(./1.jpg); 
	background-repeat: no-repeat;
	background-position: top  right;

}
	</style>
</head>
<body>
<div class="box1">

</div>
</body>
</html>

核心:水平垂直background-position: top right;,

连写:background-attachment

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		
		body
		{
			background-image: url(./1.jpg);
			background-repeat: no-repeat;
			background-attachment: fixed;
		}
	</style>
</head>
<body>
<div></div>
我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字我是文字
<br>
我是文字
<br>
我是文字
<br>
我是文字
<br>
我是文字
</body>
</html>

核心:不想滚动条随网页的滚动而滚动就设置background-attachment: fixed;,默认值scroll;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/08/31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档