css 实现折叠面板 带动画过度效果 带图标切换

通过label 的for属性和CheckBox实现  

html 

	<div class="collapse-item">
			<input type="checkbox" id="collapse1" checked name="collapse" class="collapse-toggle"></input>
			<label style="display: flex;" for="collapse1">
				<div>第一个collapse</div>
				<img class="not-show" style="width: 20px;height: 20px;" src="http://csdnimg.cn/cdn/content-toolbar/csdn-sou.png?v=1587021042">
				<img class="show" style="width: 20px;height: 20px;" src="https://img-blog.csdnimg.cn/2019091813595558.png">
			</label>
			<div class="content">
				这个是切换内容<br/>
				这个是切换内容<br/>
				这个是切换内容<br/>
				这个是切换内容<br/>这个是切换内容<br/>这个是切换内容<br/>这个是<br/>切换内容<br/>
				这个是切<br/>换<br/>内容<br/>
			</div>
		</div>

		<div class="collapse-item">
			<input type="checkbox" id="collapse2" checked="" name="collapse" class="collapse-toggle"></input>
			<label style="display: flex;" for="collapse2">
				<div>第二个collapse</div>
				<img class="not-show" style="width: 20px;height: 20px;" src="http://csdnimg.cn/cdn/content-toolbar/csdn-sou.png?v=1587021042">
				<img class="show" style="width: 20px;height: 20px;" src="https://img-blog.csdnimg.cn/2019091813595558.png">
			</label>
			<div class="content">
				这个是切换内容<br/>
				这个是切换内容<br/>
				这个是切换内容<br/>
				这个是切换内容<br/>这个是切换内容<br/>这个是切换内容<br/>这个是<br/>切换内容<br/>
				这个是切<br/>换<br/>内容<br/>
			</div>
		</div>

 

css:

.collapse-toggle{
	    		display: none;
		 }
		.content{
			max-height: 0px;
			overflow: hidden;
			transition: all .38s;
		}
		.collapse-toggle:checked~.content{
			max-height: 250px;
		}
		.collapse-toggle:checked ~label .show{
			display: none
		}
		.collapse-toggle:not(:checked) ~label .not-show{
			display: none
		}
		.collapse-item{
			margin: 10px;
			border-radius: 10px
		}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现有过渡效果的下拉框,你可以使用JavaScript和CSS来完成。下面是一种常见的实现方法: HTML结构: ```html <div class="dropdown"> <button class="dropdown-toggle" onclick="toggleDropdown()">下拉框</button> <ul class="dropdown-menu"> <li>选项1</li> <li>选项2</li> <li>选项3</li> </ul> </div> ``` CSS样式: ```css .dropdown { position: relative; display: inline-block; } .dropdown-toggle { background-color: #f1f1f1; border: none; color: black; padding: 10px; cursor: pointer; } .dropdown-menu { position: absolute; top: -100%; left: 0; background-color: #f1f1f1; list-style: none; padding: 0; margin: 0; opacity: 0; transition: opacity 0.3s ease-in-out, top 0.3s ease-in-out; } .dropdown-menu.visible { opacity: 1; top: 100%; } ``` JavaScript代码: ```javascript function toggleDropdown() { var dropdownMenu = document.querySelector('.dropdown-menu'); dropdownMenu.classList.toggle('visible'); } ``` 上面的代码实现了一个有过渡效果的下拉框。当点击下拉框按钮时,通过JavaScript的`toggleDropdown`函数切换下拉菜单的显示和隐藏状态,并使用`classList.toggle`来添加或移除`.visible`类。 在CSS中,`.dropdown`类定义了下拉框的容器样式,`.dropdown-toggle`类定义了下拉框按钮的样式,`.dropdown-menu`类定义了下拉菜单的样式。通过设置初始状态为`top: -100%`和`opacity: 0`,再通过`.visible`类来改变菜单的位置和透明度,从而实现过渡效果。 通过这种方式,你可以实现一个有过渡效果的下拉框。你可以根据需要进一步自定义样式和过渡动画。记得在HTML中给对应的元素设置相应的类名,并使用上述代码来控制它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值