Justify buttons with Bootstrap v4

前端 未结 4 1901
别跟我提以往
别跟我提以往 2021-02-01 15:00

Bootstrap v4 drops the .btn-group-justified class, see https://github.com/twbs/bootstrap/issues/17631

How to justify the button for:

 

        
4条回答
  •  眼角桃花
    2021-02-01 15:35

    Indeed the nav-justify class is missing. You can add it yourself based on TB3's code for now:

    SCSS code

    // Justified button groups
    // ----------------------
    
    .btn-group-justified {
      display: table;
      width: 100%;
      table-layout: fixed;
      border-collapse: separate;
      .btn,
      .btn-group {
        float: none;
        display: table-cell;
        width: 1%;
        .btn {
          width: 100%;
        }
        .dropdown-menu {
          left: auto;
        }
      }
    }
    

    compiled CSS code

    .btn-group-justified {
      display: table;
      width: 100%;
      table-layout: fixed;
      border-collapse: separate; }
      .btn-group-justified .btn,
      .btn-group-justified .btn-group {
        float: none;
        display: table-cell;
        width: 1%; }
        .btn-group-justified .btn .btn,
        .btn-group-justified .btn-group .btn {
          width: 100%; }
        .btn-group-justified .btn .dropdown-menu,
        .btn-group-justified .btn-group .dropdown-menu {
          left: auto; }
    

    HTML

     
    

    The above HTML code now will look like that shown in the figure beneath:

    Handling borders

    • Due to the specific HTML and CSS used to justify buttons (namely display: table-cell), the borders between them are doubled. In regular button groups, margin-left: -1px is used to stack the borders instead of removing them. However, margin doesn't work with display: table-cell. As a result, depending on your customizations to Bootstrap, you may wish to remove or re-color the borders.

    Links acting as buttons

    Dropdowns

    Use the following HTML code for dropdown buttons:

     
    

    The justified button group with dropdown button should look like that shown in the figure below:

    With

    • To use justified button groups with

    HTML

     

    The above HTML code used to justified button groups with

提交回复
热议问题