css的力量:用一個div畫圖

來源:互聯網
上載者:User
 這些圖片都是用一個DIV繪製出來的,其實原理並不複雜。


  這些圖片都是由CSS繪製出來的,通過background-image疊加實現,

  如蘑菇頭的實現,通過 radial-gradient 放射狀漸層 , linear-gradient 線性漸層相互疊加實現,如:

p {  width: 170px;  height: 140px;  background-image:        radial-gradient(circle at 50% 120%, rgba(0,0,0,0.7) 23%, rgba(0,0,0,0) 48%),        linear-gradient(30deg, rgba(0,0,0,0.4) 10%, rgba(0,0,0,0) 20%),        radial-gradient(circle at 50% 33%, #f8f6f7 32%, rgba(255,255,255,0) 32%),        radial-gradient(circle at -13% 55%, #f8f6f7 20%, rgba(255,255,255,0) 20%),        radial-gradient(circle at 113% 55%, #f8f6f7 20%, rgba(255,255,255,0) 20%),        linear-gradient(to bottom, #ef0015 20%, #b2000c 100%);        border-radius: 140px 140px 80px 80px;}

同時有前後遮擋關係的通過:before和:after虛擬元素的background-image來實現。

線上示範:http://jsfiddle.net/ourjs/ed0ayybo/

  PS: 此種手法對並不完全支援舊版IE

原文地址:http://a.singlep.com/?utm_source=ourjs.com

  • 相關文章

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.