2013-03-24 148 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