CSS3 -- API学习 (背景)

background: 

①background: red; (颜色或者url)

②background: red  top  left  no-repeat;    相当于background、position、repeat加一起一样

background-position: 左上(left top)   右上(right top)  右下(right bottom)  左下(left bottom)

background-repeat: repeat  no-repeat

background-image: url('')

background-size: 0px   0px; (宽   高)(背景是图片的时候使用)

background-origin:border-box  padding-box  context-box     (用于背景是图片的时候)

background-clip: border-box  padding-box  context-box    (用于背景是颜色的时候)

 

例子

1.背景颜色

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            div {
                border: 1px solid black;
                width: 100px;
                height: 100px;
                background: red;
                }

        </style>
    </head>
    <body>
        <div>sfdfdfdfd</div>
    </body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

结果:

2.背景图片

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            div {
                border: 1px solid black;
                width: 100px;
                height: 100px;
                background: url(u=1291417747,3760118869&fm=26&gp=0.jpg);
                background-repeat: no-repeat;
                }

        </style>
    </head>
    <body>
        <div></div>
    </body>
</html>

 

 

 

 

 

 

 

 

 

 

 

结果:

3.背景大小

①background-size:20px 20px;

②background-size:100% 100%;    填充满背景

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            div {
                border: 1px solid black;
                width: 100px;
                height: 100px;
                background: url(u=1291417747,3760118869&fm=26&gp=0.jpg);
                background-size: 100% 100%;
                background-repeat: no-repeat;
                }

        </style>
    </head>
    <body>
        <div></div>
    </body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

结果:

与上一个对比可以看出,不同     

4.background-origin 

①border-box          在盒子边框开始

②padding-box        在盒子内边距开始

③context-box         在盒子内容开始

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            div {
                border: 1px solid black;
                padding: 30px;
                width: 100px;
                height: 100px;
                background: url(u=1291417747,3760118869&fm=26&gp=0.jpg);
                background-size: 30px 30px;
                background-repeat: no-repeat;
                background-origin: padding-box;
                }

        </style>
    </head>
    <body>
        <div>ddfdff</div>
    </body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

结果:

 

clip和origin一样的效果,只不过clip修饰的是颜色。clip=context-box的结果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值