05:CSS设置背景样式

1.为内容设置背景色:background-color;
属性:
颜色;
inherit;继承父级样式

box.html

<!doctype html>
<html>
<head>
    <mate charset="utf-8">
    <title>背景</title>
    <link href="box.css" type="text/css" rel="stylesheet">

</head>
<body>
    <p为内容设置背景色:background-color;</p>
</body>
</html>

box.css

body{
    background-color:#123456;
}

2.为内容设置背景为图片background-image:url();
box.css

body{
    background-color:#123456;
    background-image:url(image.png);
}

3.固定背景图片background-attachment
(在CSS中使用 background-attachment属性可以将图片固定在浏览器上,如果拖动滚动条,背景图片不会随着网页内容的滚动而滚动,像文字浮在图片上)
属性值:
scroll;背景图片随内容滚动,默认值
fixed; 背景图片固定,不随内容滚动
inherit;继承父类样式

box.css

body{
    background-color:#123456;
    background-image:url(image.png);
    background-attachment:fixed;
    font-size: 45px;
}

4.背景图片平铺background-repeat;
属性值:
repeat;平铺背景图片;默认
no-repeat;不平铺图片;
repeat-x;在水平方向平铺
repert-y;在竖直方向平铺

box.css

 body{
    background-color:#123456;
    background-image:url(image.png);
    background-attachment:fixed;
    font-size: 45px;
    background-repeat: repeat-y;    
}

5.背景图片定位background-position
属性值:
top;顶部
center;中间
bottom;底部
right;右边
left;左边
inherit;继承父类样式
样式:
xxxpx,xxxpx;
xxx%,xxx%;
xxxpx,top;

box.css

body{
    background-color:#123456;
    background-image:url(image.png);
    background-attachment:fixed;
    font-size: 45px;
    background-repeat:no-repeat;
    background-position:left;
}
                     19:13 2018/8/17/周五
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值