CSS背景属性

请添加图片描述
CSS background-position 属性
请添加图片描述
背景图片大小
请添加图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<div>, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{height: 500px;}
        div{width: 200px;height: 1000px;background-color: brown;background-image: url(https://scpic.chinaz.net/Files/pic/pic9/202007/apic26703_s.jpg);background-repeat: no-repeat;background-position: 50% 50%;background-attachment: scroll;}
    </style>
</head>
<body>
    <div>

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

请添加图片描述
背景视觉差

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{width: 1366px;height: 768px;background: url(https://scpic1.chinaz.net/Files/pic/pic9/202011/apic29290_s.jpg);background-attachment: fixed;border-style: dotted;border-color: blue;border-width: 10px;}
        #div2{width: 1366px;height: 768px;background:url(https://scpic.chinaz.net/Files/pic/pic9/202011/bpic21782_s.jpg);background-attachment: fixed;border-right-color: brown;}
        #div3{width: 1366px;height: 768px;background:url(https://scpic.chinaz.net/Files/pic/pic9/201803/zzpic11051_s.jpg);background-attachment: fixed;}
    </style>
</head>
<body>
    <div id="div1"></div>
    <div id="div2"></div>
    <div id="div3"></div>
</body>
</html>

或者

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{height: 750px;background: url(https://scpic1.chinaz.net/Files/pic/pic9/202011/apic29290_s.jpg);background-attachment: fixed;border-style: dotted;border-color: blue;border-width: 10px;background-repeat: no-repeat;background-position: center;
        background-size: contain;}
        #div2{height: 768px;background:url(https://scpic.chinaz.net/Files/pic/pic9/202011/bpic21782_s.jpg);background-attachment: fixed;border-right-color: brown;background-repeat: no-repeat;background-position: center;
        background-size: contain;}
        #div3{height: 768px;background:url(https://scpic.chinaz.net/Files/pic/pic9/201803/zzpic11051_s.jpg);background-attachment: fixed;background-repeat: no-repeat;background-position: center;
        background-size: contain;}
    </style>
</head>
<body>
    <div id="div1"></div>
    <div id="div2"></div>
    <div id="div3"></div>
</body>
</html>

知乎案列

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        .box{
            width: 500px;
            height: 1000px;
            background: yellow; 
            margin: 0 auto;
        }
        body{
            background-image: url(http://www.leawo.cn/attachment/201310/18/1433365_1382072819epuQ.jpg);
            background-size: cover;
            background-attachment: fixed;
            background-position: center; 
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

请添加图片描述
背景的复合属性

1.用空格隔开
2.顺序可以换
3.可以只取一个值,放在后面能覆盖前面的值
4.background-size属性只能单独用

请添加图片描述
3.可以只取一个值,放在后面能覆盖前面的值(案例)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 300px;
            background-color: yellow;
            background: url(http://www.leawo.cn/attachment/201310/18/1433365_1382072819epuQ.jpg)  center; 
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

请添加图片描述
可以看出背景颜色并没有显示,在复合样式中没写,默认为白色

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值