Consistent Styling for Nested Lists with Bootstrap

前端 未结 5 1394
陌清茗
陌清茗 2020-12-22 18:39

Is there a way to make nested lists in twitter bootstrap look like a normal list, with the nested items simply indented (and have it work for an arbitrarily deep nesting)? B

5条回答
  •  半阙折子戏
    2020-12-22 19:27

    This was my approach:

        .list-group-collapse li > ul li:first-child {
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
    
        .list-group-collapse li > ul {
            margin-left: -16px;
            margin-right: -16px;
            margin-bottom: -11px;
        }
    

    If you are using BS3, then adding the .list-group-collapse class to your grouped list will do the trick. See JSFiddle: https://jsfiddle.net/oscar_dr/d2wpn8sd/1/

    Of course, you could extend BS with this class or change the values to your custom measures if you have a customized Bootstrap.

    EDIT: Added snippet to answer:

    .list-group-collapse li>ul li:first-child {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
    
    .list-group-collapse li>ul {
      margin-left: -16px;
      margin-right: -16px;
      margin-bottom: -11px;
    }
    
    
    

    With collapse


    • Level 1

      • Level 2.1

        • Item 2.1.1
        • Item 2.1.2
        • Item 2.1.3
      • Level 2.2

    Without collapse


    • Level 1

      • Level 2.1

        • Item 2.1.1
        • Item 2.1.2
        • Item 2.1.3
      • Level 2.2

提交回复
热议问题