温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

用纯css实现折叠效果的方法

发布时间:2020-09-26 11:12:18 来源:亿速云 阅读:290 作者:小新 栏目:web开发

这篇文章主要介绍了用纯css实现折叠效果的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

我们在前端页面开发过程中,折叠效果通常会用在导航栏或者下拉列表中。对于前端新手来说,可能有一定的难度。

html+css代码示例如下:

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>纯css实现折叠效果</title>
<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #parent >li> span{background: #b2ecef;display: block;width: 200px;border:1px solid #ECEEF2;}
        li {line-height: 40px;display: block;}
        li  p{
            display: inline-block;
            width: 0px;
            height: 0px;
            border-left: 5px solid transparent;
            border-right: 5px solid transparent;
            border-top: 5px solid #1094f2;
        }
        li>ul{display: none;}
        li>ul>li{border: 1px solid #DEDEDE;width: 199px;}
        #parent span:hover + ul{display: block;}
        #parent span:hover >p{
            display: inline-block;
            width: 0px;
            height: 0px;
            border-top: 5px solid transparent;
            border-bottom: 5px solid transparent;
            border-left: 5px solid#2f2f2f;}
 </style>
</head>
<body>
<ul id="parent">
    <li>
        <span><p></p>主列表</span>
        <ul>
            <li>子列表1</li>
            <li>子列表2</li>
            <li>子列表3</li>
        </ul>
    </li>
</ul>

</body>
</html>

前台最终实现折叠效果如下图:

用纯css实现折叠效果的方法

感谢你能够认真阅读完这篇文章,希望小编分享用纯css实现折叠效果的方法内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI