2013-05-29 43 views
7

我建立一個網站,這是這樣的 without expansionCSS3多邊形沒有圖像,如何?

這兩種結構的頂部AE靜態和四個底部處是動態的,當我說動,我的意思是可擴展的,這樣的事情

with expansion

由於這些都只是顏色,形狀和陰影,我相信這是可能使用CSS3來創建它們。但我很難這樣做。我甚至嘗試使用CSSHat,但結果很糟糕。

這是例子塑造 individual shape

這是生成的代碼:

width: 1920px; 
height: 341px; 
-moz-border-radius: 0 1920px 1920px/0 181px 56px; 
-webkit-border-radius: 0 1920px 1920px/0 181px 56px; 
border-radius: 0 1920px 1920px/0 181px 56px; /* border radius */ 
-moz-background-clip: padding; 
-webkit-background-clip: padding-box; 
background-clip: padding-box; /* prevents bg color from leaking outside the border */ 
background-color: #3b0f1d; /* layer fill content */ 

而結果是這樣的: converted shape 一個活生生的例子可以在這裏找到http://codepen.io/seraphzz/pen/mgDwd

哪個是實現這一目標的最佳途徑?

+0

在所有的嚴重性,如果你想在瀏覽器中創建任意形狀,CSS是可能是錯誤的工作工具。你有沒有考慮使用適當的圖形?例如,對於SVG,這將非常簡單。 – Spudley

+0

感謝您的回答Spudley,問題是我希望我的「divs」或「sections」或任何其他HTML元素具有這些形狀,這就是爲什麼我認爲我無法通過SVG實現這一點,我錯了嗎? – steps

+0

通過expandable,你的意思是說你希望它們像鼠標一樣與鼠標交互:懸停? –

回答

1

你可以使用CSS transformations:before/:after元素)來模擬效果..

喜歡的東西(在http://codepen.io/gpetrioli/pen/LHbIE演示)

<div class="background"> 
    <div class="shape"></div> 
</div> 

background{background-color: #3c101d} 
.shape{ 
    width: 800px; 
    height: 341px; 
    background: white; 
    display: block; 
    margin:10px; 
    position:relative; 
    overflow:hidden; 
} 
.shape:before{ 
    content:''; 
    width:110%; 
    height:30px; 
    background:#3c101d; 
    position:absolute; 
    height:100px; 
    top:0; 
    left:0; 
    transform-origin:0 100%; 
    transform: translateY(-100px) rotate(5deg); 
} 
.shape:after{ 
    content:''; 
    width:110%; 
    height:30px; 
    background:#3c101d; 
    position:absolute; 
    height:100px; 
    bottom:0; 
    left:0; 
    transform-origin:0 0; 
    transform: translateY(100px) rotate(-2deg); 
} 

注意:此代碼使用標準的CSS屬性。添加在需要

+0

使用谷歌瀏覽器27這個例子顯示了我一個矩形 – steps

+0

@JoãoPauloApolinárioPassos在CSS選項(請參閱http://codepen.io/seraphzz/pen/Aklfa)中啓用前綴免費或爲轉換添加webkit的供應商前綴(' -webkit變換:').. –

1

這是你的「CSSHat形」的解決方案供應商前綴的: -

<!DOCTYPE html> 
<html> 
<body> 
<style> 
    .background{ 
     background-color: #3c101d; 
     padding:22px 28px; 
     display:inline-block; 
    } 
    .shape{ 
     height: 30px; 
     border-left: 645px solid white; 
     border-top: 80px solid transparent; 
     border-bottom: 40px solid transparent; 
    } 
</style> 
<div class="background"> 
    <div class="shape"></div> 
</div> 
</body> 
</html> 

的竅門能讓你上面想要的形狀是一起玩: - 所有邊境尺寸,所有邊框顏色和或者 div的高度或寬度。

Codepen: - http://codepen.io/mrmoje/pen/EaQNOP

1

這些形狀看起來像視角轉換給我。 http://css-tricks.com/almanac/properties/p/perspective/我不認爲有一個發生器可以使左右兩端的圖像比第二個圖形的橙色部分隱藏的溢出父寬。

您可以從這個角度看到發生器,它在旋轉時可以有所有角度。 http://desandro.github.io/3dtransforms/examples/perspective-03.html

作爲替代標記而不是CSS3也並不要求圖像

我會建議使用SVG來標記所有的多邊形。所有CSS3瀏覽器都更容易和支持。

4

您可以使用CSS transforms來旋轉div。

我做了底部的div 動態,並增加了一些內容黃色綠色格。

body { 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow-x: hidden; 
 
} 
 
.top, .top2, .yellow, .green, .bottom, .bottom2 { 
 
    height: 200px; 
 
    width: 140%; 
 
    position: relative; 
 
    left: -10%; 
 
    transform-origin: 0% 100%; 
 
    transition: 0.6s ease; 
 
} 
 
.top { 
 
    top: -180px; 
 
    background: #3C101D; 
 
    transform: rotate(4deg); 
 
} 
 
.top2 { 
 
    background: #931930; 
 
    transform: rotate(-1.5deg); 
 
} 
 
.yellow { 
 
    background: #F0810E; 
 
    top: -200px; 
 
    transform: rotate(0.6deg); 
 
} 
 
.content { 
 
    display: block; 
 
    width: 65%; 
 
    position: relative; 
 
    top: 10%; 
 
    left: 10%; 
 
} 
 
.yellow .content { 
 
    transform: rotate(-0.6deg); 
 
} 
 
.green { 
 
    background: #425949; 
 
    top: -320px; 
 
    transform: rotate(-1.4deg); 
 
} 
 
.green .content { 
 
    transform: rotate(1.4deg); 
 
} 
 
.bottom { 
 
    background: #501B2B; 
 
    top: -480px; 
 
    transform: rotate(1.4deg); 
 
} 
 
.bottom2 { 
 
    background: #3C101D; 
 
    top: -600px; 
 
    transform: rotate(-0.6deg); 
 
} 
 
.yellow:hover, .green:hover, .bottom:hover, .bottom2:hover { 
 
    height: 400px; 
 
}
<div class="top"></div> 
 
<div class="top2"></div> 
 
<div class="yellow"> 
 
    <div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div> 
 
</div> 
 
<div class="green"> 
 
<div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div> 
 
</div> 
 
</div> 
 
<div class="bottom"></div> 
 
<div class="bottom2"></div>