2.CSS背景

1.CSS背景

1.CSS 背景属性用于定义 HTML 元素的背景。
2.CSS 属性定义背景效果:
background-color。定义了元素的背景颜色。
i:页面的背景颜色使用在body的选择器中:

<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style>
body
{
	background-color:#b0c4de;
}
</style>
</head>

ii:CSS中,颜色值通常以以下方式定义:十六进制、RGB、颜色名称。
background-image。元素的背景图像。
i:默认情况下,背景图像进行平铺重复显示,以覆盖整个元素实体。

<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style>
body 
{
	background-image:url('https://static.runoob.com/images/mix/paper.gif');
	background-color:#cccccc;
}
</style>
</head>

background-repeat。决定background-image 属性会在页面的水平或者垂直方向平铺。
i:水平平铺:

<style>
body
{
	background-image:url('https://static.runoob.com/images/mix/gradient2.png');
	background-repeat:repeat-x;
}
</style>

ii:不平铺:

<style>
body
{
	background-image:url('img_tree.png');
	background-repeat:no-repeat;
}
</style>

background-attachment。背景图像是否固定或者随着页面的其余部分滚动。
i:默认值为scroll:随页面滚动。fixed:不会随着页面的滚动而滚动。

<style>
body 
{
background-image:url('https://static.runoob.com/images/mix/smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>

background-position。图像定位。

<style>
body
{
	background-image:url('https://static.runoob.com/images/mix/img_tree.png');
	background-repeat:no-repeat;
	background-position:right top;
	margin-right:200px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值