css 之background (三)

作者: mochase | 来源:发表于2017-06-09 15:49 被阅读53次

background-repeat: repeat-x | repeat-y | [repeat | no-repeat | space | round]{1, 2}
一个例子:

 .demo {
        width: 100px;
        height: 100px;
        background-clip: padding-box;
        background-origin: content-box;
        padding: 20px;
        border: 20px dashed antiquewhite;
        background-repeat: repeat-x;
        background-image: url('./dog.jpg');
        background-size: 50px 40px
    }
image.png
背景图片的起点由background-origin确定,但是实际的绘图区域由background-clip确定;可以看到背景图片水平方向铺满了padding-box
spaceround属性看文档我暂时也没想明白,由于兼容性问题,有时间再研究吧

background-attachment: scroll (default) | fixed | local

fixed属性表示背景图像相对于主视口固定,但只有当容器出现在视口中时才会显示背景图像

我的一个例子

理解:
这里有两个视口,一个主视口(浏览器窗口),一个自身视口;
scroll: 当主视口滚动时,背景图片滚动;当自身视口滚动时,背景图片不滚动;
fixed: 背景图片均不滚动;
local: 背景图片均滚动;
一个例子:

        <div class="local">
            <div class="child"></div>
        </div>
        <div style="height: 1600px"></div>
    .local {
        width: 400px;
        background-image: url(./dog.jpg);
        background-repeat: no-repeat;
        background-attachment: local;
        height: 500px;
        overflow-y: scroll
    }

    .child {
        height: 600px;
    }

background-color: transparent | <color>
background-image: none | <image>

  • background-image的优先级比background-color高
  • 可以设置多组背景图片
  • 如果定义了多组背景图,且背景图之间有重叠,写在前面的将会盖在写在后面的图像之上(指定的第一个图像最接近用户)

系列到这里就结束了,前文链接:
css 之 background (一): 背景与盒模型之间的关系
css 之background (二): 背景图像的尺寸与定位

github上的完整代码
喜欢的话点个赞吧~

相关文章

  • css 之background (三)

    background-repeat: repeat-x | repeat-y | [repeat | no-rep...

  • css之background

    背景:background,把网页的背景设为图片 width 宽; height 高; background-c...

  • CSS之background

    background-color指定要使用的背景颜色 background-position指定背景图像的位置 b...

  • CSS 之 background

    background-image background-image: linear-gradient(red, g...

  • 关于背景

    background:1、css2:background:background-color || url("") ...

  • CSS3 背景

    CSS3 背景 CSS3 background-origin 属性 background-origin 属性规定背...

  • CSS背景图

    css背景图 涉及的css属性 background-image background-repeat 默认情况下,...

  • CSS3 背景

    @(HTML5)[背景] [TOC] 三、CSS3背景 CSS背景属性回顾 背景单个属性 background-i...

  • Tailwind Background

    背景滚动(background attachment) CSS提供的background-attachment属性...

  • CSS3-background扩展属性

    CSS3对background新加了3个属性,background-origin、background-clip、...

网友评论

    本文标题:css 之background (三)

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