ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

10.背景2.html

2021-09-29 17:34:31  阅读:130  来源: 互联网

标签:box 10 repeat 背景 html background position 背景图片 size


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            overflow: auto;
            width: 500px;
            height: 500px;
            background-color: #bfa;
            background-image: url("./img/3.png");
            background-repeat: no-repeat;
            background-position: 0 0;

            border: 10px red double;
            padding: 10px;
            /*
                background-clip 设置背景的范围
                    可选值
                        border-box  默认值  背景会出现在边框的下边
                        padding-box  背景不会出现在边框的下边,而只出现在内容区和内边距
                        content-box  背景只会出现在内容区
                background-origin 背景图片的偏移量计算的原点
                    可选值
                        padding-box 默认值 background-position从内边距开始计算
                        content-box 背景图片的偏移量从内容区处计算
                        border-box 背景图片的偏移量从边框处计算
             */

            background-origin: border-box;
            background-clip: content-box;

            /*
                background-size 设置背景图片的大小
                    可选值
                        - 第一个值表示宽度,第二个值表示高度
                            - 如果只写一个值,则第二个值默认是auto(等比例缩放)
                        - cover 图片的比例不变,将元素铺满
                        - contain 图片比例不变,将图片在元素中完整显示
                */
            background-size: contain;
            /*
                background-color
                background-image
                background-repeat
                background-position
                background-size
                background-origin
                background-clip
                background-attachment

                - background 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
                    并且该样式没有顺序要求,也没有哪个属性是必须写的

                    注意:
                        background-size必须写在background-position的后边,并且要用斜杠隔开
                            background-position/background-size
                        background-origin必须写在background-clip的前边

             */

        }
        .box2{
            width: 300px;
            height: 1000px;
            /* background-color: orange; */
            background-image: url("./img/2.png");
            background-repeat: no-repeat;
            /*
                background-attachment设置背景图片是否跟随元素移动
                    可选值
                        - scroll 默认值 背景图片会跟随元素移动
                        - fixed 表示背景图片会固定在页面中,不会随着元素移动
                            (结合固定定位position:fixed;理解)
             */
            background-attachment: fixed;
            background-position: 100px 100px;
        }
        .box3{
            padding: 50px;
            border: 10px red double;
            width: 500px;
            height: 500px;
            /*
                background-size必须在background-position的后边(用斜杠隔开)
                background-origin必须写在background-clip的前边

            */
            background: #bfa url("./img/2.png") center center/contain content-box content-box no-repeat;
        }
    </style>
</head>
<body>
    <!-- <div class="box3"></div> -->
    <div class="box1">
        <div class="box2">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum esse dolorum quas ab, saepe necessitatibus asperiores laudantium fugiat animi repellat neque delectus voluptas rem non veritatis quaerat. Quod, eaque nesciunt?
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Officiis id, rem enim et voluptates dolor quas laborum odio labore praesentium odit laudantium vel, veritatis ex! Doloremque consequuntur totam praesentium repudiandae?
            Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quos id repellat facilis fugiat quis earum voluptatibus commodi ab animi saepe eos dicta odio voluptate reiciendis, velit illo, quo sunt in.
        </div>
    </div>
</body>
</html>

标签:box,10,repeat,背景,html,background,position,背景图片,size
来源: https://blog.csdn.net/weixin_47952737/article/details/120552840

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有