css的border屬性實現仿圖片三角

來源:互聯網
上載者:User

實現的原來就是:在一個寬高為0像素的塊狀元素中設定border屬性,例如

 
  1. .box{  
  2. width:0px;  
  3. height:0;  
  4. border-bottom:50px #F00 solid;  
  5. border-left:50px #03F solid;  
  6. border-right: 50px #F90 solid;  
  7. border-top:50px #6C0 solid;  
  8. }  

在瀏覽器中的顯示如圖:

 
 
這樣就有上下左右四個三角形了,再把除了要用的三角外的其他3個三角(border)顏色設定為背景色就ok了。例如這樣就能得到一個顏色為#CCC的向上的三角:
 
  1. .to-top{  
  2. display:block;  
  3. overflow:hidden;  
  4. width:0px;  
  5. height:0px;  
  6. border:6px solid #ccc;  
  7. border-color:#ccc #fff;  
  8. border-width:0 6px 6px 6px;  
相關文章

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.