css3的gradient分为两种:线性渐变(linear)和径向渐变(radial)。

1、介绍

linear-gradient([设置方向],[设置开始颜色],[设置多种过度颜色],[设置结束颜色])

参数:

第一个参数:指定渐变方向,可以用“角度”的关键字或“英文”来表示:

css3 Gradient背景

第一个参数默认:180deg,等同于“to bottom”。

后面的颜色至少有2个,即开始颜色和结束颜色。

2、使用

a、举例:

<style type="text/css">
p{
    width: 300px;
    height: 100px;
    background-image:linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
}
</style>
<p>从左到右线性渐变背景</p>

css3 Gradient背景

b、一个非常酷的功能:用渐变制作导航分割线

background:linear-gradient(to bottom,#dd2926,#a82724,#dd2926) no-repeat right / 1px 15px; 意思背景使用渐变色,然后不重复,居右,斜线后面的其实是background-size的设置,width 1px,height 15px
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>CSS制作立体导航</title>
  <link rel="stylesheet" href="http://www.w3cplus.com/demo/css3/base.css">
  <style>
    body{
      background: #ebebeb;
    }
    .nav{
      width:560px;
      height: 50px;
      font:bold 0/50px Arial;
      text-align:center;
      margin:40px auto 0;
        background: #f65f57;
      /*制作圆*/
      border-radius:10px;
      /*制作导航立体风格*/
      box-shadow:0 5px rgb(176,72,63);
    }
    .nav a{
      display: inline-block;
      -webkit-transition: all 0.2s ease-in;
      -moz-transition: all 0.2s ease-in;
      -o-transition: all 0.2s ease-in;
      -ms-transition: all 0.2s ease-in;
      transition: all 0.2s ease-in;
    }
    .nav a:hover{
      -webkit-transform:rotate(10deg);
      -moz-transform:rotate(10deg);
      -o-transform:rotate(10deg);
      -ms-transform:rotate(10deg);
      transform:rotate(10deg);
    }
    .nav li{
      position:relative;
      display:inline-block;
      padding:0 16px;
      font-size: 13px;
      text-shadow:1px 2px 4px rgba(0,0,0,.5);
      list-style: none outside none;
      /*制作导航分隔线*/
      background:linear-gradient(to bottom,#dd2926,#a82724,#dd2926) no-repeat right / 1px 15px; 
    }
    /*使用伪元素制作导航列表项分隔线*/
    /*删除第一项和最后一项导航分隔线*/
    .nav li:last-child{
      background: none;
    }
    
    .nav a,
    .nav a:hover{
      color:#fff;
      text-decoration: none;
    }

  </style>
</head>
<body>
  <ul class="nav">
    <li>
      <a href="">Home</a>
    </li>
    <li>
      <a href="">About Me</a>
    </li>
    <li>
      <a href="">Portfolio</a>
    </li>
    <li>
      <a href="">Blog</a>
    </li>
    <li>
      <a href="">Resources</a>
    </li>
    <li>
      <a href="">Contact Me</a>
    </li>
  </ul>
</body>
</html>
View Code

相关文章:

  • 2022-12-23
  • 2021-05-21
  • 2021-12-18
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2022-12-23
  • 2021-09-28
  • 2021-10-19
  • 2021-12-05
相关资源
相似解决方案