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

如题所述

用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/html; charset=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实现标签折叠的解决方法。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<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>
</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>
相似回答