利用border製作三角形原理,border三角形原理
網站前端頁面中,有時候會使用一些三角形,除了使用圖片的方式之外,利用css的border屬性也可以做出相對應的三角形。那麼,利用border是如何?三角形的製作的呢?
先看下面一個例子:
CSS代碼:
width:100px; height:100px; border-top: solid 100px blue; border-left: solid 100px black; border-right: solid 100px yellow; border-bottom: solid 100px red;
運行結果:
width: 0; height: 0; border-top: solid 100px blue; border-left: solid 100px black; border-right: solid 100px yellow; border-bottom: solid 100px red;
運行結果:
width: 0; height: 0; border-left: solid 100px black; border-right: solid 100px yellow; border-bottom: solid 100px red;
運行結果:
width: 0; height: 0; border-left: solid 100px transparent; border-right: solid 100px transparent; border-bottom: solid 100px red;
運行結果:
width: 0; height: 0; border-left: solid 100px transparent; border-right: solid 100px transparent; border-bottom: solid 50px red;
運行結果:
width: 0; height: 0; border-top: solid 100px transparent; border-bottom: solid 100px transparent; border-left: solid 150px black;
運行結果:
width: 0; height: 0; border-top: solid 100px transparent; border-left: solid 150px black;
運行結果:
總結:可以通過移除一條或兩條邊框,設定相應邊框透明,實現三角形的製作,可以變換多樣,更多例子不再列舉。