用css製作三角形,理解

來源:互聯網
上載者:User

標籤:class   實現   link   lan   https   bsp   blank   pst   div   

如果真的很難理解的話,就在紙上畫那些邊框,就容易懂了

1、當如下設定代碼並賦給div相應的屬性時:

 

#sider2{

    width: 100px;

    height: 100px;

    border-top: 30px solid #000;

    border-right: 30px solid #ff0000;

    border-left: 30px solid #00ff00;

    border-bottom: 30px solid #0000ff;

}

會得到如下的一張圖:

2、接著當不設定border-bottom,即預設其為0時,可以得到下面的圖片;

3、然後當設定其width為0時,如:

4、繼續設定其height為0;

5、最後假若你把border-left,border-right設定為透明之後,就可以看到如下的三角形了。

6、這就是設定一個基本的三角形所需要的代碼,效果也看起來很直觀。

7、還有假如是想實現一個直角三角形,則最後需要兩個border邊的配合使用,瀏覽器會自動進行一些“展開變換”後就可以得到一個直角三角形。

 

#triangle-topleft {

    width: 0;

    height: 0;

    border-top: 100px solid red;

    border-right: 100px solid transparent;

}

用css製作三角形,理解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.