怎么用html和css实现标签折叠

html-css07

怎么用html和css实现标签折叠,第1张

用html和css实现标签折叠,代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>用html和css实现标签折叠</title>

</head>

<body>

<ul id="fm">

      <li><a href="#"><h1>折叠标签A</h1>

          <span>这里是描述标签A</span>

<span>这里是描述标签A</span>

<span>这里是描述标签A</span>

</a></li>

      <li><a href="#"><h1>折叠标签B</h1>

          <span>这里是描述标签B</span>

<span>这里是描述标签B</span>

<span>这里是描述标签B</span></a>

      <li><a href="#"><h1>折叠标签C</h1>

          <span>这里是描述标签C</span>

<span>这里是描述标签C</span>

<span>这里是描述标签C</span></a>

<li><a href="#"><h1>折叠标签D</h1>

          <span>这里是描述标签D</span>

<span>这里是描述标签D</span>

<span>这里是描述标签D</span></a>

  </ul>

</body>

</html>

CSS样式为:

<style type="text/css">

#fm{

  overflow:hidden

  background-color:#FFCCCC

  width:200px

  height:500px

  overflow:hidden

}

#fm h1{

  margin:0px

  color:#FF3333

  font-size:14px

}

#fm li{

  list-sytle-type:none

  display:block

  width:178px

  border:1px solid #00CCCC

  border-bottom-width:0px

}

#fm li.end{

  border-bottom-width:1px

}

#fm li a{

  display:block

  text-decoration:none

  width:100%

  padding:10px

}

#fm li a span{

  display:none

  color:#000000

  font-size:12px

  padding-top:10px

}

#fm li a:hover{

  background:#fff

}

#fm li a:hover span{

  display:block

  cursor:hand

}

</style>

效果如图:

以上就是用html和css实现标签折叠的解决方法。

可以改变 "div" 元素的高度(jQuery的animate方法):

$(".btn1").click(function(){

  $("#box").animate({height:"300px"})

})

也可以设置溢出隐藏:

<div style="min-height:10pxoverflow:hidden">

    <div style="margin-top:-800px">content more..</div>

</div>

第二种方式也需要js动态改变div style里面的margin-top。

transition-property :规定设置过渡效果的css属性名称(默认值all)

transition-duration :规定完成过渡效果需要多少秒或毫秒(默认0s)

transition-timing-function :指定过渡函数,规定速度效果的速度曲线(默认为ease函数)

transition-delay :指定开始出现的延迟时间(默认延迟0s)

注意:transition四个子属性之间只能用空格隔开,不能用逗号隔开