css代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #div1 { 200px; height: 200px; border: 1px solid #333; background: -webkit-linear-gradient(top,red,yellow); /* chrome */ background: -ms-linear-gradient(top,red,yellow); /* IE10及以上 */ background: -moz-linear-gradient(top,red,yellow); /* 火狐 */ background: linear-gradient(top,red,yellow); /* 兼容 */ } </style> </head> <body> <div id="div1"></div> </body> </html>
效果如下: