助你美化網站的實用css3技巧(1)

       CSS3 規範讓前端開發人員可以建立出各類複雜的視覺效果,使網站更好看,更可以吸引用戶訪問。這篇文章中,我收集了一組實用的 CSS3 技巧,可以幫助你美化您的網站,並給它一個更專業的外觀和感受。css

黑白圖像前端

下面的 CSS 代碼可以把彩色圖像轉變成黑白風格:web

    img.desaturate { 網站

        filter: grayscale(100%);spa

        -webkit-filter: grayscale(100%);開發

        -moz-filter: grayscale(100%);input

        -ms-filter: grayscale(100%);it

        -o-filter: grayscale(100%);io

    }class

頁面頂部陰影

下面這個簡單的 CSS3 代碼片斷能夠給網頁加上漂亮的頂部陰影效果:

    body:before {

          content: "";

          position: fixed;

          top: -10px;

          left: 0;

          width: 100%;

          height: 10px;

          -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);

          -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);

          box-shadow: 0px 0px 10px rgba(0,0,0,.8);

          z-index: 100;

    }

檢測鼠標雙擊

無論您相信與否,使用 CSS 就可以檢測出元素是否被雙擊:

HTML

    <div class="test3">

      <span><input type="text" value=" " readonly="true" />

      <a href="http://www.baidu.com">Double click me</a></span>

    </div>

CSS

    .test3 span {

      position: relative;

    }

    .test3 span a { 

      position: relative;

      z-index: 2; 

    }

    .test3 span a:hover, .test3 span a:active { 

      z-index: 4; 

    }

    .test3 span input { 

      background: transparent; 

      border: 0; 

      cursor: pointer; 

      position: absolute; 

      top: -1px; 

      left: 0; 

      width: 101%; 

      height: 301%; 

      z-index: 3; 

    }

    .test3 span input:focus { 

      background: transparent; 

      border: 0; 

      z-index: 1; 

    }

css實現三角形

這實際上是一個古老的技巧,不須要用到 CSS3 新特性就能實現:

    div.arrow-up {

      width:0px; 

      height:0px; 

      border-left:5px solid transparent;

      border-right:5px solid transparent; 

      border-bottom:5px solid #2f2f2f; 

      font-size:0px;

      line-height:0px;

    }

    div.arrow-down {

      width:0px; 

      height:0px; 

      border-left:5px solid transparent;

      border-right:5px solid transparent;

      border-top:5px solid #2f2f2f;

      font-size:0px;

      line-height:0px;

    }

    div.arrow-left {

      width:0px; 

      height:0px; 

      border-bottom:5px solid transparent;

      border-top:5px solid transparent; 

      border-right:5px solid #2f2f2f;

      font-size:0px;

      line-height:0px;

    }

div.arrow-right {

  width:0px; 

  height:0px; 

  border-bottom:5px solid transparent;  

  border-top:5px solid transparent; 

  border-left:5px solid #2f2f2f; 

  font-size:0px;

  line-height:0px;

}

相關文章
相關標籤/搜索