Twitter bootstrap 3.0 icon change on collapse

前端 未结 10 1270
长发绾君心
长发绾君心 2020-12-04 19:41

This is about Bootstrap 3.0. I would like the icon/glyphicon to change on collapse. I.e, from a closed folder to an open one.

I have searched far and wide, and have

10条回答
  •  误落风尘
    2020-12-04 20:12

    Using only CSS, the bootstrap collapse icon can be changed with your predefined icons:

    a[aria-expanded=true] .glyphicon-plus {
        display: none;
    }
    a[aria-expanded=false] .glyphicon-minus {
        display: none;
    }
    .pointer{
      cursor:pointer;
    }
    
    
    
    
    
    

    In your HTML add aria-expanded="false" and add two icons what you need to set in your collapse bar. Like,

    
    

    And control it from css. When collapse bar expand then

    a[aria-expanded=true] .glyphicon-plus {
        display: none;
    }
    

    otherwise it will be

    a[aria-expanded=false] .glyphicon-minus {
        display: none;
    }
    

    Run the snippet and I think you just need this...

提交回复
热议问题