垂直渐变:上->下
垂直渐变:下->上
水平渐变:左->右
水平渐变:右->左
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<style type="text/css"> .test1{ width: 80%; min-height: 80px; text-align: center; line-height: 80px; color: White; font-size: 20px; filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#00BFFF',endColorStr='#0000CD',gradientType='0'); background: -moz-linear-gradient(top, #00BFFF, #0000CD); background: -o-linear-gradient(top,#00BFFF, #0000CD); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#00BFFF), to(#0000CD)); } .test2{ width: 80%; min-height: 80px; text-align: center; line-height: 80px; margin-bottom: 10px; color: White; font-size: 20px; filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#00BFFF',endColorStr='#0000CD',gradientType='0'); background: -moz-linear-gradient(bottom, #00BFFF, #0000CD); background: -o-linear-gradient(bottom,#00BFFF, #0000CD); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#00BFFF), to(#0000CD)); } .test3 { width: 45%; min-height: 80px; text-align: center; line-height: 80px; margin-bottom: 10px; color: White; font-size: 20px; filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#00BFFF',endColorStr='#0000CD',gradientType='1'); background: -moz-linear-gradient(left, #00BFFF, #0000CD); background: -o-linear-gradient(left,#00BFFF, #0000CD); background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#00BFFF), to(#0000CD)); } .test4 { width: 45%; min-height: 80px; text-align: center; line-height: 80px; margin-bottom: 10px; color: White; font-size: 20px; filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#00BFFF',endColorStr='#0000CD',gradientType='1'); background: -moz-linear-gradient(right, #00BFFF, #0000CD); background: -o-linear-gradient(right,#00BFFF, #0000CD); background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#00BFFF), to(#0000CD)); } </style> <div> <div class="test1">垂直渐变:上->下</div> <div class="test2">垂直渐变:下->上</div> </div> <div> <div class="test3" style="display: inline-block;">水平渐变:左->右</div> <div class="test4" style="display: inline-block;">水平渐变:右->左</div> </div> |
IE系列
filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#00BFFF',endColorStr='#0000CD',gradientType='0');
参数:startColorStr起始颜色 endColorStr结束颜色 gradientType为0时代表垂直,为1时代表水平
Firefox
background: -moz-linear-gradient(top, #00BFFF, #0000CD);
参数:top、bottom垂直,left、right水平 例如:top时从顶部由#00BFFF到#0000CD渐变,bottom时从底部由#00BFFF到#0000CD渐变
Opera
background: -o-linear-gradient(top,#00BFFF, #0000CD);
参数:top、bottom垂直,left、right水平 例如:top时从顶部由#00BFFF到#0000CD渐变,bottom时从底部由#00BFFF到#0000CD渐变
webkit,如Chrome、Safari等
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#00BFFF), to(#0000CD));
参数:linear线性, x1 x2, x3 x4 x1与x3相同时垂直,x2与x4相同时水平 from起始颜色 to结束颜色