Quantcast
Channel: w3cplus
Viewing all articles
Browse latest Browse all 1557

纯css3手风琴效果1

$
0
0
纯css3手风琴效果1

本实例通过对radio按钮的状态判断来实现折叠效果。主要应用的是兄弟元素选择器~,注意这个兄弟元素选择器只选择后面的兄弟元素,对于同级的前面的兄弟元素css3还没有响应的选择器。然后综合应用:before和transition来实现前面图标的切换及高度的伸展动画。这个高度的伸展变化必须设置一个具体的值,如为auto则没有transition动画效果,只是切换而已。

demodownload

css主要代码为:

#accordion{
	border:1px solid #D2D2D2;
	border-top:none;
	width:600px;
}
#accordion input[type='radio']{
	display:none;
}
#accordion label{
	display:block;
	font-size:16px;
	background-color:#F4F4F4;
	border-top:1px solid #D2D2D2;
	line-height:36px;
	font-weight:bold;
}
#accordion label:before{
	content:"\2610";
	background-color:#fff;
	width:19px;
	height:19px;
	-moz-border-radius:10px;
	-webkit-border-radius:10px;
	border-radius:10px;
	text-align:center;
	margin:0 5px;
	box-shadow:0 0 1px rgba(0,0,0,0.5);
	display:inline-block;*display:inline;*zoom:1;
	line-height:19px;
	vertical-align:middle;
}
#accordion .accordion-content{
	height:0;
	overflow:hidden;
	-webkit-transition:height 0.3s ease;
	-moz-transition:height 0.3s ease;
	-ms-transition:height 0.3s ease;
	-o-transition:height 0.3s ease;
	transition:height 0.3s ease;
}
#accordion .accordion-content p{
	margin:10px;
}
#accordion input:checked + label:before{
	content:"\2611";
	color:#f00;
	box-shadow:0 0 2px rgba(255,0,0,0.5);
}
#accordion input:checked ~ .accordion-content{
	height:100px;
}

demodownload


Viewing all articles
Browse latest Browse all 1557

Trending Articles