CSS揭秘 第二章 背景与边框

半透明边框

body{
    background: url("02.jpg") no-repeat;
}
.box{
    width: 200px;
    height:150px;
    margin: 40px ;
    border:30px solid hsla(0,0%,20%,.5);
    background: white;
    background-clip: padding-box;/*内边距的外沿把背景裁切掉*/
}

这里写图片描述

多层边框

1.box-shadow

.box{
    width: 150px;
    height:150px;
    margin: 40px ;
    background: yellowgreen;
    color:white;
    box-shadow:0 0 0 10px #665,0 0 0 20px deeppink,0 0 0 30px blue;
}

这里写图片描述

2.outline

.box{
    width: 150px;
    height:150px;
    margin: 40px ;
    background: yellowgreen;
    border:10px solid #665;
    color:white;
    outline: 10px solid deeppink;
}

这里写图片描述

3.outline-offset

.box{
    width: 400px;
    height:150px;
    margin: 40px ;
    background: black;
    border-radius:5px;
    color:white;
    text-align: center;
    outline:1px dashed white;
    outline-offset: -10px ;
}

这里写图片描述

4.缺点

.box{
    width: 400px;
    height:150px;
    margin: 40px ;
    background: black;
    outline:10px solid yellowgreen;
    border-radius:5px;
    color:white;
    text-align: center;
}

这里写图片描述

灵活的背景定位

1.background-position

.box{
    width:250px;
    height: 200px;
    background: url("pizza.svg") no-repeat bottom right yellow;
    /*回退方案:不支持background-position属性时,就添加bottom right*/
    background-position: right 40px bottom 40px;
}

这里写图片描述

2.background-origin

这里写图片描述

默认情况下:我们写的left,bottom等属性值是以Padding Box为基准的
可以通过设置padding值,并使图标位置从Content Box开始,

.box{
    width:250px;
    height: 200px;
    background: url("pizza.svg") no-repeat bottom right yellow;
    padding: 40px;
    background-origin: content-box;
}

这里写图片描述

3.calc()函数
注意!!!千万要在calc()函数的“+”“-”运算符两侧加一个空白符号

.box{
    width:250px;
    height: 200px;
    background: url("pizza.svg") no-repeat yellow;
    background-position: calc(100% - 40px) calc(100% - 20px);
}

这里写图片描述

边框内圆角

1.运用两个div

*{
    padding: 0;
    margin: 0;
}
.outter_box{
    width: 400px;
    color: white;
    background: #655;
    padding: .8em;
}
.inner_box{
    background: tan;
    border-radius: .8em;
    padding: 1em;
}

这里写图片描述

2.box-shadow和border-radius

.box{
    width: 400px;
    color: white;
    background: tan;
    padding: 1em;
    box-shadow: 0 0 0 .6em #665;
    border-radius: .8em;
    outline: .6em solid #666655;
}

这里写图片描述

条纹背景

1.等宽双色条纹

.box{
    width: 400px;
    height: 200px;
    background:linear-gradient(yellow  50%,pink 50%);
    background-size: 100% 50px;
}

这里写图片描述
2.不等宽双色条纹
只需要改变色标的值,但要保证两个颜色百分比依然一致,

.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(yellow 30%,pink 30%);
    background-size: 100% 50px;
}

这里写图片描述

//或者
.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(yellow 30%,pink 0);
    background-size: 100% 50px;
}

3.多色条纹
方法(1)

.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(yellow 33.3%,pink 33.3%,pink 66.6%,cornflowerblue 66.6%);
    background-size: 100% 60px;
}

方法(2)

如果某个色标的位置值比整个列表中在它之前的色标的位置值都小,则该色标的位置值就会被设置为它前面所有色标的位置值的最大值

这就意味着,如果我们把第二个色标值设为0,那它总是会被浏览器调整为前一个色标值

.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(yellow 33.3%,pink 0,pink 66.6%,cornflowerblue 0);
    background-size: 100% 60px;
}

这里写图片描述
4.竖状条纹

.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(to right ,yellow 33.3%,pink 0,pink 66.6%,cornflowerblue 0%);
    background-size: 30px 100%;
}

这里写图片描述
5.斜向条纹
方法(1)

.box{
    width: 400px;
    height: 250px;
    background:linear-gradient(45deg ,yellow 25%,pink 0,pink 50%,yellow 0,yellow 75%,pink 0);
    background-size: 50px 50px;
}

这里写图片描述
方法(2)

.box{
     width: 300px;
     height:300px;
     background:repeating-linear-gradient(45deg,yellow, yellow 30px,pink 0,pink 60px);
    }

这里写图片描述

6.任意角度的斜向条纹

.box{
    width: 300px;
    height:300px;
    background:repeating-linear-gradient(80deg,yellow, yellow 30px,pink 0,pink 60px);
    }

这里写图片描述
7.灵活的同色系条纹
方法(1)

 .box{
       width: 300px;
       height:300px;
       background:repeating-linear-gradient(30deg,#79b, #79b 30px,#58a 0,#58a 60px);
      }

这里写图片描述
方法(2)

简写语法:两个连续色标具有相同颜色和不同的位置

 .box{
      width: 300px;
      height:300px;
      background: #5588aa;
      background-image:repeating-linear-gradient(30deg, hsla(0,0%,100%,.1),hsla(0,0%,100%,.1) 15px,transparent 0,transparent 30px);
      }

这里写图片描述

复杂的背景图案

网格
水平和垂直条纹叠加

 .box{
      width: 300px;
      height:300px;
      background: white;
      background-image:linear-gradient(90deg, rgba(200,0,0,.5) 50%, transparent 0),
                       linear-gradient(rgba(200,0,0,.5) 50%, transparent 0);
     background-size: 50px 50px;
      }

这里写图片描述
规定网格间隙

 .box{
      width: 300px;
      height:300px;
      background: #58a;
      background-image:linear-gradient(white 1px, transparent 0),
                       linear-gradient( 90deg,white 1px, transparent 0);
      background-size: 50px 50px;
      }

这里写图片描述
波点

 .box{
      width: 300px;
      height:300px;
      color:white;
      background: #655;
      background-image:radial-gradient(tan 50%, transparent 0);
      background-size: 50px 50px;
     }

这里写图片描述

 .box{
         width: 300px;
         height:300px;
         color:black;
         background: gainsboro;
         background-image:radial-gradient(tan 30%, transparent 0),
                            radial-gradient(tan 30%, transparent 0);
         background-size: 50px 50px;
         background-position: 0 0,25px 25px;
      }

这里写图片描述

棋盘

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值