用css实现背景渐变
2016-08-25 16:28
691 查看
css3:linear-gradient
比如:黑色变成白色
.gradient{
background:
-moz-linear-gradient(top, #000000 0%, #ffffff 100%);
background:
-webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#ffffff));
background:
-webkit-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
-o-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
-ms-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
linear-gradient(to bottom, #000000 0%,#ffffff 100%);
}
案例:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>CSS linear-gradient()详解-CSS教程</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<style>
div{width:200px;height:100px;margin-top:10px;border:1px solid #ddd;}
.test{
background:-moz-linear-gradient(#fff,#333);
background:-webkit-gradient(linear,center top,center
bottom,from(#fff),to(#333));
background:-webkit-linear-gradient(#fff,#333);
background:-o-linear-gradient(#fff,#333);
background:-ms-linear-gradient(#fff,#333);
background:linear-gradient(#fff,#333);}
.test2{background:-moz-linear-gradient(#000,#f00 50%,#090);background:-webkit-gradient(linear,center top,center bottom,from(#000),color-stop(.5,#f00),to(#090));background:-webkit-linear-gradient(#000,#f00 50%,#090);background:-o-linear-gradient(#000,#f00 50%,#090);background:-ms-linear-gradient(#000,#f00
50%,#090);background:linear-gradient(#000,#f00 50%,#090);}
.test3{background:-moz-linear-gradient(left center,#000 20%,#f00 50%,#090 80%);background:-webkit-gradient(linear,left center,right center,color-stop(.2,#000),color-stop(.5,#f00),color-stop(.8,#090));background:-webkit-linear-gradient(0deg,#000 20%,#f00 50%,#090
80%);background:-o-linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);background:-ms-linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);background:linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);}
.test4{background:-moz-linear-gradient(45deg,#000,#f00 50%,#090);background:-webkit-gradient(linear,left bottom,right top,from(#000),color-stop(.5,#f00),to(#090));background:-webkit-linear-gradient(45deg,#000,#f00 50%,#090);background:-o-linear-gradient(45deg,#000,#f00
50%,#090);background:-ms-linear-gradient(45deg,#000,#f00 50%,#090);background:linear-gradient(45deg,#000,#f00 50%,#090);}
</style>
</head>
<body>
<div class="test"></div>
<div class="test2"></div>
<div class="test3"></div>
<div class="test4"></div>
</body>
</html>
效果图:
![](http://img.blog.csdn.net/20160825163219354?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
比如:黑色变成白色
.gradient{
background:
-moz-linear-gradient(top, #000000 0%, #ffffff 100%);
background:
-webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#ffffff));
background:
-webkit-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
-o-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
-ms-linear-gradient(top, #000000 0%,#ffffff 100%);
background:
linear-gradient(to bottom, #000000 0%,#ffffff 100%);
}
案例:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>CSS linear-gradient()详解-CSS教程</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<style>
div{width:200px;height:100px;margin-top:10px;border:1px solid #ddd;}
.test{
background:-moz-linear-gradient(#fff,#333);
background:-webkit-gradient(linear,center top,center
bottom,from(#fff),to(#333));
background:-webkit-linear-gradient(#fff,#333);
background:-o-linear-gradient(#fff,#333);
background:-ms-linear-gradient(#fff,#333);
background:linear-gradient(#fff,#333);}
.test2{background:-moz-linear-gradient(#000,#f00 50%,#090);background:-webkit-gradient(linear,center top,center bottom,from(#000),color-stop(.5,#f00),to(#090));background:-webkit-linear-gradient(#000,#f00 50%,#090);background:-o-linear-gradient(#000,#f00 50%,#090);background:-ms-linear-gradient(#000,#f00
50%,#090);background:linear-gradient(#000,#f00 50%,#090);}
.test3{background:-moz-linear-gradient(left center,#000 20%,#f00 50%,#090 80%);background:-webkit-gradient(linear,left center,right center,color-stop(.2,#000),color-stop(.5,#f00),color-stop(.8,#090));background:-webkit-linear-gradient(0deg,#000 20%,#f00 50%,#090
80%);background:-o-linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);background:-ms-linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);background:linear-gradient(0deg,#000 20%,#f00 50%,#090 80%);}
.test4{background:-moz-linear-gradient(45deg,#000,#f00 50%,#090);background:-webkit-gradient(linear,left bottom,right top,from(#000),color-stop(.5,#f00),to(#090));background:-webkit-linear-gradient(45deg,#000,#f00 50%,#090);background:-o-linear-gradient(45deg,#000,#f00
50%,#090);background:-ms-linear-gradient(45deg,#000,#f00 50%,#090);background:linear-gradient(45deg,#000,#f00 50%,#090);}
</style>
</head>
<body>
<div class="test"></div>
<div class="test2"></div>
<div class="test3"></div>
<div class="test4"></div>
</body>
</html>
效果图:
相关文章推荐
- HTML+CSS基础课程之包含(后代)选择器
- CSS3实现3D方块旋转
- 选择器
- css3 图片旋转效果 以y轴翻转效果等
- css 单行和多行文本溢出显示省略号
- 苹果手机下不是a标签却有了a标签的样式的解决方案
- CSS快速学习8:圆角切图、滚动条和图片整合技术
- 【css3初级】transition过渡效果写法,鼠标放到图片上图片变小
- css3,居中文字,居中对齐,文字两端对齐
- CSS简介、编写CSS代码的方式、HTML和CSS注释
- CSS:CSS层叠样式表的概述
- css3弹性盒子如何布局
- dedecms 模型新添加的自定义字段设置样式
- 不要忘了css3动画效果transform 和过渡效果 transition:属性 时间 运动效果 延迟时间;
- 设置css通用字体
- 电商网页布局+动态实现
- CSS特殊符号的特殊性
- 福昕阅读器中书签里面页面跳转保持适合宽度样式
- CSS基础之样式
- HTML基础样式(三)