.tab-content{
max-height: 0;
overflow: hidden;
-webkit-transition: max-height .8s;
-moz-transition: max-height .8s;
-ms-transition: max-height .8s;
-o-transition: max-height .8s;
transition: max-height .8s;
} .tab{
list-style-type: none;
list-style-image: none;
margin: 0;
padding: 0;
margin-top: 10px;
overflow: hidden; border:1px solid #CCC;
border-radius:5px; /* 动画差 */ -webkit-transition: max-height .2s;
-moz-transition: max-height .2s;
-ms-transition: max-height .2s;
-o-transition: max-height .2s;
transition: max-height .2s; } .tab h2{
cursor:pointer;
padding:10px 20px;
background: #EEE;
border-top:1px solid #BBB;
border-bottom:1px solid #BBB;
margin:-1px 0;
color:#333; -webkit-transition: background .3s;
-moz-transition: background .3s;
-ms-transition: background .3s;
-o-transition: background .3s;
transition: background .3s;
} .tab h2:hover{
background: lightblue;
} .tab h2:hover ~ .tab-content{// 开始动画
max-height: 200px;
}
 <h1>CSS3 缓动手风琴动画效果(一丝)</h1>
<p>使用「max-height」实现自适应高度</p>
<ul class="tab">
<li>
<h2>选项卡1</h2>
<div class="tab-content">
<p>隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
</p>
</div>
</li>
<li>
<h2>选项卡2</h2>
<div class="tab-content">
<p>隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字
</p>
</div>
</li>
</ul>

<!doctype html>
<html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/ayayak/1/edit
-->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 优先使用IE最新版本和 Chrome -->
<meta name ="viewport" content ="initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-title" content="测试">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="format-detection" content="telephone=no" />

<title>CSS3 缓动手风琴动画效果-by 一丝</title>
<style>
*{-webkit-tap-highlight-color: rgba(0,0,0,0);}

</style>

<style id="jsbin-css">
*{
margin: 0;
padding: 0;
}
body{
font-family: 'helvetica neue', 'hiragino sans gb', stheiti,'wenquanyi micro hei',\5FAE\8F6F\96C5\9ED1,\5B8B\4F53, sans-serif;
font-size: 14px;
}

h1{
font-size: 22px;
}

h2{
font-size: 18px;
font-weight: normal;
}

.main{
width:360px;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
}

ul{
list-style-type: none;
list-style-image: none;
}
p{
line-height: 1.8;
margin:15px 20px;
}

.tab-content{
max-height: 0;
overflow: hidden;
-webkit-transition: max-height .8s;
-moz-transition: max-height .8s;
-ms-transition: max-height .8s;
-o-transition: max-height .8s;
transition: max-height .8s;
}

.tab{
margin-top: 10px;
overflow: hidden;

border:1px solid #CCC;
border-radius:5px;

/* 动画差 */

-webkit-transition: max-height .2s;
-moz-transition: max-height .2s;
-ms-transition: max-height .2s;
-o-transition: max-height .2s;
transition: max-height .2s;

}

.tab h2{
cursor:pointer;
padding:10px 20px;
background: #EEE;
border-top:1px solid #BBB;
border-bottom:1px solid #BBB;
margin:-1px 0;
color:#333;

-webkit-transition: background .3s;
-moz-transition: background .3s;
-ms-transition: background .3s;
-o-transition: background .3s;
transition: background .3s;
}

.tab h2:hover{
background: lightblue;
}

.tab h2:hover ~ .tab-content{
max-height: 200px;
}
</style>
</head>
<body>
<div class="main">
<h1>CSS3 缓动手风琴动画效果(一丝)</h1>
<p>使用「max-height」实现自适应高度</p>
<ul class="tab">
<li>
<h2>选项卡1</h2>
<div class="tab-content">
<p>隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
</p>
</div>
</li>
<li>
<h2>选项卡2</h2>
<div class="tab-content">
<p>隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字<br>
隐藏的文字
</p>
</div>
</li>
</ul>
</div>

</body>
</html>

运行代码

使用「max-height」实现自适应高度的更多相关文章

  1. 怎样让自定义Cell的图片和文本自适应高度

    Let's do it! 首先创建一个Model类 包括一个图片名称属性 还有文字内容属性 #import <Foundation/Foundation.h> @interface Mod ...

  2. Html-Css-iframe的自适应高度方案

    先看一个示例,有两个页面,1.html通过iframe嵌入2.html,两个页面都是同域的 a.html <!DOCTYPE html> <html> <head> ...

  3. 网页制作技巧:iframe自适应高度

    转自:http://www.enet.com.cn/article/2012/0620/A20120620126237.shtml 通过Google搜索iframe 自适应高度,结果5W多条,搜索if ...

  4. [转载]再谈iframe自适应高度

    Demo页面:主页面 iframe_a.html ,被包含页面 iframe_b.htm 和 iframe_c.html 下面开始讲: 通过Google搜索iframe 自适应高度,结果5W多条,搜索 ...

  5. iframe框架自适应高度 uncanght SecurityError: Blocked a frame with origin "null" from accessing a frame ....

    来源于crm项目的contact/edit.html 一.背景是这样的 最近在做crm系统的前端页面,有一个页面呢,点击“查看全部信息”时会弹出,这个弹窗里面又有分页导航,分页不是使用ajax 异步刷 ...

  6. 关于使用iframe标签自适应高度的使用

    在ifrome内设定最小高度,(此方法只适用于页面内切换高度不一.但是会保留最大高度,返回后保持最大高度不再回到最初页面的高度) <iframe id="one4" widt ...

  7. Iframe 自适应高度

    网页中,经常遇见嵌套问题.我们怎么解决好点,我个人喜欢使用 Html 中的 Iframe 标签.忘记在哪里找的代码了. Iframe 的代码: <iframe src="indexpa ...

  8. IOS Swift语言开发 tableView的重用以及自cell的自适应高度

    http://www.aichengxu.com/iOS/11143168.htm 一.准备数据 (这是一个元组,第一个元素为英雄的名字;第二个元素为英雄头像图片的名字,格式为.PNG,如果为其他的格 ...

  9. 「Android 开发」入门笔记

    「Android 开发」入门笔记(界面编程篇) ------每日摘要------ DAY-1: 学习笔记: Android应用结构分析 界面编程与视图(View)组件 布局管理器 问题整理: Andr ...

随机推荐

  1. hdu3270Arranging Your Team(dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=3720 #include <iostream> #include<cstdio> #inc ...

  2. jQuery_效果(淡入淡出)

    1.jQuery fadeIn() 方法( 用于淡入已隐藏的元素.) 语法: $(selector).fadeIn(speed,callback); 可选的 speed 参数规定效果的时长.它可以取以 ...

  3. laravel中的$request对象构造及请求生命周期

    laravel应用程序中index.php是所有请求的入口.当用户提交一个form或者访问一个网页时,首先由kernel捕捉到该session PHP运行环境下的用户数据, 生成一个request对象 ...

  4. 嵌入式ARM系统开发基础

    从.net到delplhi 从windows到Linxu 未来有多远? 如何突破自己? 什么是自己? 我从哪里来,要到哪里去? 世界是什么? 是世选择了我,还是我选择了世界? 怎么才能够完成蜕变? 去 ...

  5. Codeforces Round #276 (Div. 2)

    A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...

  6. PHP实现站点pv,uv统计(三)

    数据分析脚本如下: //error_reporting(0);date_default_timezone_set("PRC");$environment = get_cfg_var ...

  7. XE7 - 程序图标及启动画面图片的注意事项

    还是继续昨晚写的,年前已经解决了这个问题,现在补记下.启动画面失真是本篇笔记的重点.搜索了很多文章,基本上大同小异,几乎都没怎么提及启动画面失真的问题.不知道是不是我的操作不对头,. Project ...

  8. HDU 1423 Greatest Common Increasing Subsequence

    最长公共上升子序列   LCIS 看这个博客  http://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.html #include&l ...

  9. oracle interval-partition 解决range分区大难题

    博客<oracle分区>中讲了oracle的几种分区,并且对于oracle的典型分区如Range分区和List分区给了示例. 在实际运用Range分区时,遇到了这样的难题: createt ...

  10. JS面向对象组件(五) -- 复制对象(拷贝继承)

    研究到这儿,竟然出现了一个面试题目 var a = { name : '小明' }; var b = a; b.name = '小强'; alert( a.name ); 结果必然是“小强”,原因是对 ...