08 背景设置

1 背景颜色 background-color

默认情况下,背景颜色background-color:transparent; 表示无颜色,透明色。


2 背景图片

参数值作用
repeat背景图像在纵向和横向上平铺
no-repeat背景图像不平铺
repeat-x背景图像在横向上平铺
repeate-y背景图像在纵向上平铺

 

背景平铺设置:background-repeat:repeat;

背景图片设置 background-image:none (默认情况下)

通常情况下,background-image:url(路径);

小试牛刀:以此表示no-repeat;repeat;repeat-x; repeat-y.

   

  

代码展示:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>背景</title>
		<style type="text/css">
			div {
			width: 800px;
			height:800px;
			/* 平铺 */
			/* 页面可以添加背景颜色也可以添加背景图片,但是背景图片在背景颜色的上方. */
			background-color: aliceblue;
			background-image: url(../image/aoteman.jpg);
			/* 表示不平铺 */
			/* background-repeat: no-repeat; */
			/* 表示平铺 */
		/* 	background-repeat: repeat; */
			/* 表示演x平铺 */
			/* background-repeat:repeat-x; */
			/* 表示演y平铺 */
			background-repeat:repeat-y;
		}
		</style>
		
	</head>
	<body>
		<div id="">
			
		</div>
	</body>
</html>

3 背景方位

通过css背景属性,可以给页面元素添加背景样式;背景属性可以设置背景颜色、背景图片、背景平铺、背景图片位置、背景图像固定

背景图片位置    background-position: x   y;

精确定位:background-position: 20px  50px;

混合模式:background-position:center 20px;

参数值说明
length百分数|由浮点数字和单位标识符组成的长度值
positiontop、center、bottom、left、center、right

 

实际案例:

          

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>背景</title>
		<style type="text/css">
			div {
			width: 800px;
			height:800px;
			/* 平铺 */
			/* 页面可以添加背景颜色也可以添加背景图片,但是背景图片在背景颜色的上方. */
			background-color: aliceblue;
			background-image: url(../image/aoteman.jpg);
			background-repeat: no-repeat;
			/* 方位 */
		/* 	background-position: center right; */
			background-position: top left;
		}
		</style>
		
	</head>
	<body>
		<div id="">
			
		</div>
	</body>
</html>

4 案例1

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>英雄联盟背景</title>
		<style type="text/css">
			h1 {
				font-weight: 400;
				background-image: url(../image/default.png);
				background-repeat: no-repeat;
		/* 		背景位置居中靠左 */
				background-position: center left;
				/* 文字缩进2.5em */
				text-indent: 2.5em;
			}
		</style>
	</head>
	<body>
		<h1>亲爱的召唤师,欢迎登陆</h1>
	</body>
</html>

5 案例2

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>英雄联盟背景</title>
		<style type="text/css">
			body {
				background-image: url(../image/YJH.jpg);
				background-position: top center;
				background-repeat: no-repeat;
			}
		</style>
	</head>
	<body>
		
	</body>
</html>


6 背景固定

固定:   background-attachment: fixed;          字体滚动,图片固定

滚动:   background-attachment: scroll;    (默认) :字体和图片一块滚动


7  背景属性的简洁写法

background: 背景颜色  背景图片地址  背景平铺  背景图像滚动  背景图片位置;

中间用空格隔开

background: #FF0000 url(../image/YJH.jpg) repeat fixed top center;


8 css的背景

颜色背景半透明的效果

background: rgba(0,0,0,0.3);

最后一个参数是alpha透明度,取值介于0到1之间,0表示完全无颜色,1表示全颜色

background-color:balck;  相当于background: rgba(1,1,1,1);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在uni-app中添加背景图片有几种方式可以实现。第一种方式是使用CSS的background-image属性来设置背景图。你可以将图片地址直接作为url传入background-image属性中,例如: background-image: url("https://su.bcebos.com/shitu-query-nj/2021-07-21/15/ba8d23f1085c34d8?authorization=bce-auth-v1/7e22d8caf5af46cc9310f1e3021709f3/2021-07-21T08:13:52Z/300//ca431ab8970c8573f59a105c98dc4ace6d7b461b234aca196bf35c018a645744"); 这种方式适用于大图片的引入。第二种方式是使用uni-app的image标签来引入图片,并设置其为背景图。你可以在template中使用image标签,并设置其src属性为图片路径。然后在style区域中,通过设置position、width、height等属性来控制图片的位置和大小。例如: <template> <view class="container"> <image class="bg-img" src="图片路径"></image> <view class="content"></view> </view> </template> <style> .bg-img { position: fixed; width: 100%; height: 100%; top: 0; left: 0; z-index: -1; } </style> 这种方式适用于小图片的引入。此外,uni-app官方文档也提到了使用image标签引入背景图的方式,官方文档中说明了src属性支持相对路径、绝对路径和base64码。所以你可以尝试使用网络地址或者相对路径来引入背景图片。例如: <template> <view class="container"> <image class="bg-img" src="../static/iconimg/l1.png"></image> <view class="content"></view> </view> </template> 其中,../static/iconimg/l1.png是相对路径的示例,你可以根据自己的实际情况替换为正确的图片路径。总之,根据你的需求和图片的大小,你可以选择合适的方式来添加背景图片到uni-app中。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值