渐变
效果:
文件目录:
代码:
HTML代码:
<!DOCTYPE html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS渐变</title>
<link rel="stylesheet" href="../CssFile/index.css" type="text/css">
</head>
<body>
<h3>线性渐变 - 使用不同的角度</h3>
<div id="grad1" style="color:white; text-align: center;">0deg</div>
<br>
<div id="grad2" style="color:white; text-align: center;">90deg</div>
<br>
<div id="grad3" style="color:white;">180deg</div>
<br>
<div id="grad4" style="color:white;">-90deg</div>
<p>为了添加透明度,我们使用 rgba() 函数来定义颜色结点。rgba() 函数中的最后一个参数可以是从 0 到 1 的值,它定义了颜色的透明度:0 表示完全透明,1 表示完全不透明。</p>
<div id="grad5">aa</div>
<p><strong>注意:</strong> Internet Explorer 9 及之前的版本不支持渐变。</p>
</body>
</html>
CSS代码:
h3
{
text-align: center;
}
div
{
text-align: center;
width: 60%;
margin-left: auto;
margin-right: auto;
}
body
{
text-align: center;
}
#grad1
{
height: 100px;
background: -webkit-linear-gradient(0deg, #43fff7, blue); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(0deg, red, blue); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(0deg, red, blue); /* Firefox 3.6 - 15 */
background: linear-gradient(0deg, red, blue); /* 标准的语法(必须放在最后) */
}
#grad2
{
height: 100px;
background: -webkit-linear-gradient(90deg, red, #37ff3c, #276fd2, blue); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(90deg, red, #37ff3c, #276fd2, blue); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(90deg, red, #37ff3c, #276fd2, blue); /* Firefox 3.6 - 15 */
background: linear-gradient(90deg, red, #37ff3c, #276fd2, blue); /* 标准的语法(必须放在最后) */
}
/**
不平均渐变
*/
#grad3
{
height: 100px;
background: -webkit-linear-gradient(180deg, red 20%, #37ff3c 30%, #276fd2 10%, blue 40%); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(180deg, red 20%, #37ff3c 30%, #276fd2 10%, blue 40%); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(180deg, red 20%, #37ff3c 30%, #276fd2 10%, blue 40%); /* Firefox 3.6 - 15 */
background: linear-gradient(180deg, red 20%, #37ff3c 30%, #276fd2 10%, blue 40%); /* 标准的语法(必须放在最后) */
}
#grad4
{
height: 100px;
background: -webkit-linear-gradient(-90deg, red, blue); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(-90deg, red, blue); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(-90deg, red, blue); /* Firefox 3.6 - 15 */
background: linear-gradient(-90deg, red, blue); /* 标准的语法(必须放在最后) */
}
#grad5 {
height: 200px;
background: -webkit-linear-gradient(left, rgba(255,0,0,0), rgba(255,0,0,1)); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(right, rgba(255,0,0,0), rgba(255,0,0,1)); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(right, rgba(255,0,0,0), rgba(255,0,0,1)); /* Firefox 3.6 - 15 */
background: linear-gradient(to right, #6ca3ff, #6855ff); /* 标准的语法(必须放在最后) */
}
JS代码:
无