2013-11-01 79 views
1

我想知道是否有一種方法來適應邊框或輪廓屬性只有可見部分的div。適合邊框/輪廓可見css

我想在我製作的三角形上放一個邊框,我也對jQuery有一個公平的把握,但是我更願意在固執的css中完成這一切。

這裏是我的代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org  /TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>former</title> 
<style type="text/css"> 
.trekant { 
      height:0px; 
      width:0px; 
     border-top:0px solid; 
     border-right:40px solid;/*controls angle of right corner*/ 
     border-bottom:100px solid;/*controls bottom line width*/ 
     border-left:40px solid;/*controls angle of left corner*/ 
     border-color: transparent transparent #E6DD6E transparent; 
     margin:30px auto 0 auto; 
     outline:solid #000; 
} 
</style> 
</head> 
<body> 
<div class="trekant"> 
</div> 
</body> 
</html> 

謝謝:)

+2

你舉的例子是奇。你有一個名爲'.triangle'的'div',和'.trekant'的CSS設置。這有什麼關係? –

回答

1

也許這:

.trekant:before { 
    content:''; 
    border-top:0px solid; 
    border-right:41px solid; 
    border-bottom:101px solid; 
    border-left:41px solid; 
    position:absolute; 
} 

能擺弄寬度border-widthtop/left性能。

編輯回覆:嘗試創建一個:重疊a:之前具有類似的屬性(除了「主要元素」的相對位置和:之前和:絕對之後),然後使用jquery進行傳統支持。只要確保重疊的三角形比下面的三角形寬1px,並將其定位爲負數。如果那有意義的話。

像這樣:

<body><div><div class="triangle"></div></div></body> 

的這樣:

body > div {position:relative;width:50%;margin:20px} 
.triangle:before { 
    content:''; 
    width:0; 
    height:0; 
    border-width:0 10px 10px 10px; 
    border-style:solid; 
    border-color:transparent transparent #ccc transparent; 
    z-index:2; 
    position:absolute; 
    left:0; 
    top:0; 
} 
.triangle:after { 
    content:''; 
    width:0; 
    height:0; 
    border-width:0 12px 12px 12px; 
    border-style:solid; 
    border-color:transparent transparent #000 transparent; 
    z-index:1; 
    position:absolute; 
    left:-2px; 
    top:-1px; 
} 

http://jsfiddle.net/4hQ4z/

+0

好想法!必須明天圍繞代碼包裝我的頭,將報告與最終解決方案。 – user2945025