美文网首页
章节(23) 背景相关

章节(23) 背景相关

作者: 壹点微尘 | 来源:发表于2017-05-28 11:20 被阅读16次

一. 背景尺寸属性

1.什么是背景尺寸属性
背景尺寸属性是CSS3中新增的一个属性, 专门用于设置背景图片大小

background-size:xxxx;
取值:
1.具体像素 >> background-size:200px 100px;
2.百分比 >> background-size:100% 80%;
3.宽度等比拉伸 >> background-size:auto 100px;
4.高度等比拉伸 >> background-size:100px auto;
5.cover >> background-size:cover;
  • 5.1告诉系统图片需要等比拉伸
  • 5.2告诉系统图片需要拉伸到宽度<a>和</a>高度都填满元素
6. contain >> background-size:contain;
  • 6.1告诉系统图片需要等比拉伸
  • 6.2告诉系统图片需要拉伸到宽度<a>或</a>高度都填满元素(<a>只保证一边填满</a>)
background-size

二. 背景图片定位区域属性

<a>background-origin</a> : 告诉系统背景图片从什么区域开始显示,默认情况下就是从padding区域开始显示;

取值:

1.<a>padding-box</a>:默认值 >>background-origin: padding-box; 告诉系统背景图片从什么区域开始显示,默认情况下就是从padding区域开始显示;
2.<a>border-box</a> >> background-origin:border-box; 从border位置开始
3.<a>content-box</a> >> background-origin:content-box;从content位置开始

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>113-背景图片定位区域属性</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul li{
            list-style: none;
            float: left;
            width: 100px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            border: 20px dashed #000;
            padding: 50px;
            margin-left: 20px;
            background: url("images/dog.jpg") no-repeat;
        }
        ul li:nth-child(2){
            /*
            告诉系统背景图片从什么区域开始显示,
            默认情况下就是从padding区域开始显示
            */
            background-origin: padding-box;
        }
        ul li:nth-child(3){
            background-origin:border-box;
        }
        ul li:nth-child(4){
            background-origin:content-box;
        }
    </style>
</head>
<body>
<ul>
    <li>默认</li>
    <li>padding</li>
    <li>border</li>
    <li>content</li>
</ul>
</body>
</html>
背景图片定位区域属性

三. 背景绘制区域属性

<a>background-clip:xxx;</a>背景绘制区域属性是专门用于指定从哪个区域开始绘制背景的, 默认情况下会从border区域开始绘制背景

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>114-背景绘制区域属性</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul li{
            list-style: none;
            float: left;
            width: 100px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            border: 20px dashed #000;
            padding: 50px;
            margin-left: 20px;
            background: red url("images/dog.jpg") no-repeat;
        }
        ul li:nth-child(2){
            /*
            背景绘制区域属性是专门用于指定从哪个区域开始绘制背景的, 默认情况下会从border区域开始绘制背景
            */
            background-clip: padding-box;
        }
        ul li:nth-child(3){
            background-clip: border-box;
        }
        ul li:nth-child(4){
            background-clip: content-box;
        }
    </style>
</head>
<body>
<ul>
    <li>默认</li>
    <li>padding</li>
    <li>border</li>
    <li>content</li>
</ul>
</body>
</html>
背景绘制区域属性(红色为绘制区域)

四. 多重背景图片

<a>先添加的背景图片会盖住后添加的背景图片</a>

元素c3之后可以设置多张背景图片
多张背景图片之间用逗号隔开即可

background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom;
注意点:

先添加的背景图片会盖住后添加的背景图片

background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom,url("images/animal4.png") no-repeat right bottom,url("images/animal5.png") no-repeat center center;

建议在编写多重背景时拆开编写

background-image: url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png");
background-repeat: no-repeat, no-repeat, no-repeat;
background-position: left top, right top, left bottom;

完整代码如下:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>115-多重背景图片</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 500px;
            height: 500px;
            border: 1px solid #000;
            margin: 0 auto;
            /*
            多张背景图片之间用逗号隔开即可
            注意点:
            先添加的背景图片会盖住后添加的背景图片
            建议在编写多重背景时拆开编写
            */
            /*background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom,url("images/animal4.png") no-repeat right bottom,url("images/animal5.png") no-repeat center center;*/
            background-image: url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png");
            background-repeat: no-repeat, no-repeat, no-repeat;
            background-position: left top, right top, left bottom;
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>
多重背景图片

四.多重背景图片联系

<a>先添加的背景图片会盖住后添加的背景图片</a>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>116-多重背景图片-练习</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 600px;
            height: 190px;
            border: 1px solid #000;
            margin: 100px auto;
          //由于先添加的背景图片会盖住后添加的背景图片,故先添加飞机,太阳;后添加白云;
            background-image: url("images/bg-plane.png"),url("images/bg-sun.png"), url(images/bg-clouds.png);
            background-repeat: no-repeat, no-repeat, no-repeat;
            background-size: 50px 50px, 50px 50px, auto auto;//由于白云的图片尺寸为2247*190,保持它原有的就尺寸可以了
            background-position: 50px 150px, 400px 50px, 0px 0px;
            animation: move 10s linear 0s infinite normal;
        }
        @keyframes move {
            from{
                background-position: 50px 150px, 400px 50px, 0px 0px;
            }
            to{
                background-position: 500px -150px, 400px 50px, -600px 0px;//让云朵往左运动
            }
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>
蓝天白云

相关文章

  • 章节(23) 背景相关

    一. 背景尺寸属性 1.什么是背景尺寸属性背景尺寸属性是CSS3中新增的一个属性, 专门用于设置背景图片大小 ba...

  • 章节1背景

    我是1991年生人,出生在河北省某个地区的农村。 父亲,是个医生,至少是村里的赤脚医生,走街串巷,看...

  • 背景相关

    1.什么是背景尺寸属性 背景尺寸属性是CSS3中新增的一个属性, 专门用于设置背景图片大小 背景图片定位区域属性 ...

  • day23-CSS-背景相关属性

    背景尺寸属性 CSS3中新增属性,专门用于设置背景图片大小 取值background-size:x轴 y轴默认具体...

  • 背景相关-1

    1-颜色 background:颜色; 没有附加颜色值时候的显示如下图: 2颜色的三种写法和显示展示 首先,建立几...

  • 摄影学习(3)

    背景 两种背景:相关背景、纯色背景(来自B站“二麦科技”) 相关背景 (逆光,左侧遮光,制造明暗对比,产生层次感)...

  • 历史一轮复习必修1《辛亥革命》补充资料

    人教版历史老课本相关章节

  • 分布式系统监控(六)- 预警

    背景 前面一章节介绍了如何使用storm将日志信息进行实时统计,并将相关信息汇总为指标模型的数据。在实际业务场景中...

  • 背景图相关

    1. 设背景图div一定要指定宽高,否则图片不显示 2. 缩小拉大窗口时背景图片也跟着缩放 3. 背景图不重复: ...

  • CSS 背景相关属性

    重要代码background (背景)background-image:(背景图片)url("./文件夹/二级文件...

网友评论

      本文标题:章节(23) 背景相关

      本文链接:https://www.haomeiwen.com/subject/xggcfxtx.html