CSS3已經開創了一種新的前端設計方式,可以用它來制作各種樣式的圖表。以下是一些關于如何用CSS3設計圖表的參考:
/*樣式一: 餅圖*/ .pie-chart { width: 200px; height: 200px; border-radius: 50%; overflow: hidden; position: relative; } .pie-chart:before { content: ""; width: 100%; height: 100%; border-radius: 50%; position: absolute; top: 0; left: 0; transform: rotate(0deg); transform-origin: center center; box-shadow: inset 0 0 0 100px #fff; animation: rotate 5s linear forwards; } @keyframes rotate { 0% { transform: rotate(0deg); box-shadow: inset 0 0 0 100px #fff; } 100% { transform: rotate(360deg); box-shadow: inset 0 0 0 100px #00bcd4; } } /*樣式二: 柱狀圖*/ .bar-chart { width: 400px; height: 300px; position: relative; background-color: #F7F7F7; } .bar { width: 50px; position: absolute; bottom: 0; background-color: #00bcd4; transition: height 1s ease; } .bar:first-child { left: 50px; } .bar:nth-child(2) { left: 150px; } .bar:last-child { left: 250px; } .bar:hover { height: 200px; } /*樣式三: 折線圖*/ .line-chart { width: 400px; height: 300px; position: relative; background-color: #F7F7F7; } .points { display: flex; justify-content: space-between; position: absolute; bottom: 0; left: 0; right: 0; height: 250px; } .point { width: 15px; height: 15px; border-radius: 50%; background-color: #00bcd4; position: relative; } .point:before { content: ""; width: 2px; height: 100%; background-color: #00bcd4; position: absolute; bottom: -100%; left: 50%; transform: translateX(-50%); } .point:hover:before { bottom: 0; } .line { width: 2px; background-color: #00bcd4; position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); z-index: -1; } .line:before { content: ""; width: 100%; height: 2px; background-color: #00bcd4; position: absolute; top: 50%; left: -50%; } .line:hover:before { left: 0; }
以上是三種樣式的圖表的CSS代碼,我們可以在HTML中引用,然后根據需要添加數據、樣式等,即可制作出個性化的、美觀的圖表。
下一篇jquery a js