Bootstrap 3: Span elements floating right in list-group-item do not consume vertical space

前端 未结 2 1537
遥遥无期
遥遥无期 2021-01-30 10:48

In a Bootstrap 3 list-group-item, I have an icon, some text, and two icons / buttons that should float right.

I tried this:



        
相关标签:
2条回答
  • 2021-01-30 11:41

    To keep the buttons aligned wrap a new element around them and float the wrapping element. Then clear the float on list items with the .clearfix class to fix their height.

    <div class="list-group">
      <a href="#" class="list-group-item clearfix">
        <span class="glyphicon glyphicon-file"></span>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit.
        <span class="pull-right">
          <button class="btn btn-xs btn-info">CCS</button>
          <button class="btn btn-xs btn-warning">
            <span class="glyphicon glyphicon-trash"></span>
          </button>
        </span>
      </a>
    </div>
    

    See live example here: http://jsfiddle.net/cdog/EpG7x/.

    However, placing buttons within a link is not valid according to the HTML5 specification from W3C.

    The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).

    A similar result can be achieved using panels with tables instead.

    <div class="panel panel-default">
      <table class="table table-hover">
        <tbody>
          <tr>
            <td>
              <span class="glyphicon glyphicon-file"></span>
              Lorem ipsum dolor sit amet, consectetur adipisicing elit.
            </td>
            <td class="text-right text-nowrap">
              <button class="btn btn-xs btn-info">CCS</button>
              <button class="btn btn-xs btn-warning">
                <span class="glyphicon glyphicon-trash"></span>
              </button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    

    To prevent content inside a cell from wrapping, you can use the .text-nowrap class (added in Bootstrap v3.2.0).

    See live example here: http://jsfiddle.net/cdog/6mFDH/.

    0 讨论(0)
  • 2021-01-30 11:50
    <li class="list-group-item d-flex justify-content-between align-items-center">
    Text Here
    <a href="javascript:void(0);" onclick="Delete('')"><i class="fas fa-trash-alt"></i></a>
    </li>
    

    This will work for bootstrap 4.0 latest v

    0 讨论(0)
提交回复
热议问题