.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. 1141. RSA Attack(RSA)

    1141 越来越喜欢数论了 很有意思 先看个RSA的介绍 RSA算法是一种非对称密码算法,所谓非对称,就是指该算法需要一对密钥,使用其中一个加密,则需要用另一个才能解密. RSA的算法涉及三个参数,n ...

  2. 3D volume texture和cube map

    cube map texture可以理解为6个面的纸盒, sample的时候使用vector射线型的sample. volume texture可以理解是一摞2D texture,sample的时候用 ...

  3. Jquery和一些Html控件

    1.1 Jquery中如何获取各种Html控件的值    1.$("#ID").val();    2.Check获取选中的值:$("#ID").is(&quo ...

  4. UVa 10815 Andy's First Dictionary

    感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...

  5. Drawable和Bitmap的区别

    Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...

  6. [Swift系列]001-入门准备

    [引子] 最新的苹果发布会上公布了新的苹果编程语言Swift,并且演示了Xcode 6 Beta的一些新功能. 据苹果公司称,这个新语言开放的API更多,实用起来更方便,总之是值得学习.使用,比C/o ...

  7. jquery响应回车事件

    简单地记下jquery实现回车事件,代码如下: 全局: $(function(){document.onkeydown = function(e){     var ev = document.all ...

  8. matlab注释使用,以及相应的注释快捷键

    1.多行注释 单行注释是加% %{ 若干语句 %} 2.快捷键 多行注释: 选中要注释的若干语句, 编辑器菜单Text-<Comment, 或者快捷键Ctrl+R 取消注释: 选中要取消注释的语 ...

  9. java中对浮点数精度的处理DecimalFormat

    DecimalFormat是一个队浮点数进行格式化输出的利器,比如我们要输出一个保留一位小数的浮点数,可以键入如下代码: DecimalFormat df = new DecimalFormat(&q ...

  10. 多线程&多进程解析:Python、os、sys、Queue、multiprocessing、threading

    当涉及到操作系统的时候,免不了要使用os模块,有时还要用到sys模块. 设计到并行程序,一般开单独的进程,而不是线程,原因是python解释器的全局解释器锁GIL(global interpreter ...