当前位置:主页 > 查看内容

CSS3条纹背景制作的实战攻略

发布时间:2021-10-14 00:00| 位朋友查看

简介:mozilla内核浏览器制作background背景渐变 1、制作一个简单的橫条纹渐变背景 -mozilla内核的浏览器css样式: CSS Code 复制内容到剪贴板 body{ background-color : #aaa ; background-image :-moz-linear-gradient( #000 25%, #fc0 80%); background - size……

mozilla内核浏览器制作background背景渐变

1、制作一个简单的橫条纹渐变背景

-mozilla内核的浏览器css样式:

CSS Code复制内容到剪贴板
  1. body {   
  2.  background-color#aaa;   
  3.  background-image:-moz-linear-gradient(#000 25%,#fc0 80%);   
  4.  background-size50px 50px;   
  5. }  

以火狐为代表,显示效果如下:
2016531114556815.jpg (411×106)

改变background-size的值可以控制背景条纹的高度。上例中-moz-linear-gradient的值分为两组,开始值和结束值,同时设定的开始值的开始位置和结束值的结束位置,位置相差的部分形成渐变。开始位置之前的部分填充为开始的颜色值,结束值之后的部分填充为结束的颜色值。

2、改变条纹的方向

CSS Code复制内容到剪贴板
  1. body {   
  2.  background-image:-moz-linear-gradient(0deg,#000 25%,#fc0 80%);   
  3. }  

在上面的样式中添加了一组参数<角度位置>,参数分别为0deg-360deg,当这为0deg时,为竖条纹,度数增加时,以逆时针方向转动。下图为它分别为0deg和45deg时效果图:
2016531114631103.jpg (319×120)

2016531114649581.jpg (301×120)

3、我们尝试着多加几种颜色渐变

CSS Code复制内容到剪贴板
  1. body {   
  2.  background-image:-moz-linear-gradient(45deg,#000 25%,transparent 25%,#fc0 80%);   
  3. }  

大家看到,在原来的代码里面我添加了一种透明颜色(transparent 25%),这种渐变的位置和前面一种渐变的位置相重合,它发生了什么样的事情?
2016531114715279.jpg (264×113)

从上图中大家可以清晰的看到,第一种颜色嘎然而止。那我们再试着多添加几种这样的颜色,会出现什么样的效果?写到这里我打算把里面的角度先调成0deg,这样看起来会更清楚。

CSS Code复制内容到剪贴板
  1. body {   
  2.  background-image:-moz-linear-gradient(0deg,#000 25%,transparent 25%,transparent 50%,#fc0 50%,#f00 75%,transparent 75%);   
  3. }  

猜猜看,效果图会是什么样子的?
2016531114803691.jpg (278×111)

在这里大家一定要注意一个问题,这里面写了background-size:50px,50px;那么,它可以被分成重复的块,每个块是50px*50px,注意每个块的起始位置和结束位置。

4、斜纹背景的雏形

现在大家再把原来的0deg,改成45deg,会变成什么样子的呢?
2016531114835228.jpg (308×151)

大家应该可以看出来这已经是斜纹背景了吧。再修改一下:

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-image:-moz-linear-gradient(45deg,#000 25%,transparent 25%,transparent 50%,#000 50%,#000 75%,transparent 75%);   
  3.     background-size:16px 16px;   
  4. }  

大家看到了什么,有没有得到令你满意的效果,修改颜色值,来达到你的目的。这里面还有一个问题,大家自己思考下吧,background-size的值需要注意什么?
2016531114906725.jpg (307×138)

5、最终效果

虽然上面的斜纹背景已经出来了,但还没有达到我们想要的最终效果。我们再把里面的颜色值修改一下,换成白色。现在的颜色值为#fff,我们把它换成rgba形式为rgba(255,255,255,1),前面的三个数字为rgb,第四个数字为alpha,现在我们把这个alpha改成半透明的,代码如下:

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-color#eee;   
  3.     background-image: -moz-linear-gradient(45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);   
  4.     background-size16px 16px;   
  5. }  

webkit内核
 1、制作一个简单的竖条纹背景

css如下, 这里的效果图可以与上面火狐版的对应起来看

CSS Code复制内容到剪贴板

  1. body {   
  2.     background-color#eee;   
  3.     background-image:-webkit-gradient(linear,0 0,100% 0,from(#fff),to(#000));   
  4.     background-size80px 80px;   
  5. }  

 2、改变条纹的方向,

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-image:-webkit-gradient(linear,0 100%,100% 0,from(#fff),to(#000));   
  3. }  

 3、添加丰富的颜色渐变

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-image:-webkit-gradient(linear,0 0,100% 0,from(#fff),to(#000),color-stop(25%,#fc0),color-stop(50%,#0fc),color-stop(75%,#f0c))   
  3. }  

 4、调整颜色,并添加透明色。


复制代码
代码如下:
background-image:-webkit-gradient(linear,0 0,100% 0,color-stop(25%,#0fc),color-stop(25%,transparent),color-stop(50%,transparent),color-stop(50%,#fc0),color-stop(75%,#f0c),color-stop(75%,transparent));

 5、按第2步来调整方向


复制代码
代码如下:
background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(25%,#0fc),color-stop(25%,transparent),color-stop(50%,transparent),color-stop(50%,#fc0),color-stop(75%,#f0c),color-stop(75%,transparent));

  6、调整颜色,调整background-size大小

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(25%,#000),color-stop(25%,transparent),color-stop(50%,transparent),color-stop(50%,#000),color-stop(75%,#000),color-stop(75%,transparent));   
  3.     background-size16px 16px;   
  4. }  

2016531115330310.jpg (600×300)

7、调整颜色值的透明度,最终效果如下:

虽然上面的斜纹背景已经出来了,但还没有达到我们想要的最终效果。我们再把里面的颜色值修改一下,换成白色。现在的颜色值为#fff,我们再把它换成rgba形式为rgba(255,255,255,1),前面的三个数字为rgb,第四个数字为alpha,现在我们把这个alpha改成半透明的,最终代码如下:

CSS Code复制内容到剪贴板
  1. body {   
  2.     background-color#eee;   
  3.     background-image: -moz-linear-gradient(45deg,#fff 25%, transparent 25%, transparent 50%,#fff 50%,#fff 75%, transparent 75%, transparent);   
  4.     background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(25%,rgba(255,255,255,0.2)),color-stop(25%,transparent),color-stop(50%,transparent),color-stop(50%,rgba(255,255,255,0.2)),color-stop(75%,rgba(255,255,255,0.2)),color-stop(75%,transparent));   
  5.     background-size16px 16px;   
  6. }  

上面的代码加上了上面讲的mozilla内核浏览器下的写法,在火狐、谷歌浏览器中测试显示正常。
2016531115224102.jpg (346×180)


原文链接:https://m.jb51.net/css/464766.html
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:移动端Web页面的CSS3 flex布局快速上手指南 下一篇:没有了

推荐图文


随机推荐