8.14作业

背景:

引入图片:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 500px;
            height: 400px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

背景图片的平铺:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 8000px;
            height: 8000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
            /* 背景图片的平铺: */
            background-repeat: repeat;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

      

水平方向平铺:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 8000px;
            height: 8000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 水平方向平铺 */
            background-repeat: repeat-x;   
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

垂直方向平铺:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 8000px;
            height: 8000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            background-repeat: repeat-y;   
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

不平铺:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 8000px;
            height: 8000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            /* background-repeat: repeat-y; */
            /* 不平铺: */
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

背景图片的定位移动:

第一个数值代表水平方向,第二个数值代表垂直方向

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            /* background-repeat: repeat-y; */
            /* 不平铺: */
            background-repeat: no-repeat; 
            /*  背景图片的定位移动: */
            background-position: center;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

背景图片的固定方式:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            /* background-repeat: repeat-y; */
            /* 不平铺: */
            background-repeat: no-repeat; 
            /*  背景图片的定位移动: */
            background-position: center;
            /* 背景图片的固定方式 */
            background-attachment: fixed;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

背景图片大小:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            /* background-repeat: repeat-y; */
            /* 不平铺: */
            background-repeat: no-repeat; 
            /*  背景图片的定位移动: */
            background-position: center;
            /* 背景图片的固定方式 */
            background-attachment: fixed;
            /* 背景图片大小 */
            background-size: contain;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            /* 引入图片 */
            background-image: url(../baidu.jpeg);
             /* 垂直方向平铺 */
            /* background-repeat: repeat-y; */
            /* 不平铺: */
            background-repeat: no-repeat; 
            /*  背景图片的定位移动: */
            background-position: center;
            /* 背景图片的固定方式 */
            background-attachment: fixed;
            /* 背景图片大小 */
            background-size: cover;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

以上两种其中contain:以最短边为 参照物按比例放大

cover:以最长边为参照

auto:为自适应

如果写数值第一个数值代表水平方向

第二个数值代表垂直方向

背景图片的显示区域:

背景图片开始平铺:

border-box:从边框开始平铺

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            border: 30px dotted #000;
            background-image: url(../baidu.jpeg);
            background-repeat: no-repeat;
            background-origin: border-box; 
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

padding-box:默认值,从内边距开始平铺

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            border: 30px dotted #000;
            background-image: url(../baidu.jpeg);
            background-repeat: no-repeat;
            background-origin: padding-box; 
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

content-box:从内容开始平铺

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 1000px;
            background-color: aqua;
            border: 30px dotted #000;
            background-image: url(../baidu.jpeg);
            background-repeat: no-repeat;
            padding: 50px;
            background-origin: content-box; 
        }
    </style>
</head>
<body>
    <div>背景图片</div>
</body>
</html>

background-clip:平埔到哪里结束(裁切的时候结束位置不能比开始位置小)

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
         body {
            background-color: #000;
          }
          div {
            width: 500px;
            height: 300px;
            border: 20px solid #aaa;
            background-image: url(../baidu.jpeg);
            font: bold 100px/100px "微软雅黑"; 
            text-align: center;
            line-height: 290px;
            background-clip: text;
            color: transparent;
            transition: all 100S linear;
            margin: 100px;
          }
          div:hover {
            background-position:500px 100px;
          }
    </style>
</head>
<body>
    <div>风景真好</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值