Pure CSS Collapse Accordion

前端 未结 3 488
青春惊慌失措
青春惊慌失措 2021-01-24 20:00

I have a CSS collapse accordion with just pure CSS, it is working perfect.

I have just 1 issue: right now if the user click in any label: Label One, Label Two, Label Thr

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 20:34

    if you want to use Jquery this code may help you

    this is html

    title 1
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    title 2
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    title 3
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    this is css

    .title{
                text-decoration: none;
                font-size: 17px;
                display: block;
                padding: 10px;
                background: #ccc;
                color: #fff;
                border-bottom:1px solid #fff;
            }
            .group .content{
                display: none;
                padding: 10px;
                background: #43ad43;
                color: #fff;
            }
            .open .title{
                background: green !important;
                border-bottom:none;
            }
            .open .content{
                display: block;
            }
    

    and this is jquery

    $(document).ready(function () {
            $('.title').on('click',function (e) {
                e.preventDefault();
                var parent=$(this).parent();
    
    
                if (parent.hasClass('open')) {
                   parent.removeClass('open')
                }
                else{
                    $(".group").removeClass("open");
                    parent.addClass("open");
                }
    
            })
        });
    

提交回复
热议问题