2012-04-20 98 views
0

我想創建一個正方形,並在它的頂部僅適用於CSS三角形,所以如何用ccs創建三角形和正方形?

  1. 我可以寫在三角形
  2. 一些動態文本它會很容易地動態設置的三角形色彩搭配在運行時的CSS。
+1

可能的重複[如何CSS CSS三角形工作?](http://stackoverflow.com/questions/7073484/how-does-this-css-triangle-shape-work) – Jon 2012-04-20 08:14:57

+1

檢查到此並創建任何形狀http: //css-tricks.com/examples/ShapesOfCSS/ – 2012-04-20 09:03:17

回答

0

下面是做這件事的一種方法:

http://jsfiddle.net/VWdxj/

HTML

<div class="container"> 
    <div class="content">Hello World</div> 
    <div class="triangle"></div> 
</div> 

CSS

.container{ 
    border:1px solid #000; 
    position:relative; 
} 
.content{ 
    z-index:500; 
    position:absolute; 
    top:230px; 
    left:120px; 
    color:#fff; 
} 
.triangle{ 
    border-color: #fff #fff red #fff; 
    border-width:160px; 
    border-style:solid; 
    width:0; 
    height:0; 
    position:absolute; 
    top:0; 
    left:0; 
    z-index:2; 
}