2013-03-24 146 views
-1

在我負責前端開發的日子裏,我只能通過CSS和JavaScript實現展開/摺疊行爲。 已經可以在CSS3中完全編寫一個展開/摺疊解決方案嗎?在CSS3中完全展開/摺疊

編輯: 我打算做的是類似this,但這裏它正在使用jQuery。

+0

你能懸停做到這一點,或單擊只?如果只點擊,這隻能用CSS來完成。 – Mooseman 2013-03-24 17:48:06

+3

那麼,它*可能會完全在CSS中展開/摺疊。我已經完成了,但這也取決於你想要的展開/摺疊功能的複雜程度。沒有關於你想要做什麼的細節,我們無法真正幫助你。 – animuson 2013-03-24 17:48:16

+0

@Mooseman其實它取決於... – PeeHaa 2013-03-24 17:51:26

回答

2

如從here借用和稍微調整:

/* Default State */ 
div { 
    background: green; 
    width: 400px; 
    height: 100px; 
    line-height: 100px; 
    color: white; 
    text-align: center; 
    display: none; 
} 

/* Toggled State */ 
input[type=checkbox]:checked ~ div { 
    display: block 
} 

Fiddle

高級展示與淡入這裏:(編輯,並不需要如關鍵幀在評論中指出了!)http://jsfiddle.net/Dxvf7/2/

/* Default State */ 
div.container > div { 
    background: green; 
    width: 400px; 
    height: 100px; 
    line-height: 100px; 
    color: white; 
    text-align: center; 
    opacity: 0; 
    height: 0; 
    -webkit-transition: all 2s linear; 
    -moz-transition: all 2s linear; 
    -o-transition: all 2s linear; 
    transition: all 2s linear; 
} 
/* Toggled State */ 
div.container > input[type=checkbox]:checked ~ div { 
    opacity: 1; 
    height: auto; 
} 
+2

爲什麼不使用CSS轉換?該代碼對於它正在執行的基本功能來說過於複雜... – animuson 2013-03-24 18:53:37

+0

您能詳細闡述一下嗎? – utxeee 2013-03-24 20:56:50

+0

@utxeee你是什麼意思? – 2013-03-24 21:11:47