html - 如何将按钮 anchor 元素放置在父元素的最右边

标签 html twitter-bootstrap css

我无法在父元素的右侧设置名为 “Refer Me”anchor 标签。请注意,我不想硬编码 CSS 的任何值。我想使用标准的 Bootstrap 类。

工作示例:

“推荐我”按钮呈现正常。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="bs-example" style="right-padding:140px;" data-example-id="panel-without-body-with-table">
  <div class="panel panel-default">
    <div class="panel-heading">Panel heading<a href="#" class="btn btn-primary">Refer Me </a></div>
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Mark</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Jacob</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Larry</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

无效示例:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="bs-example" style="right-padding:140px;" data-example-id="panel-without-body-with-table">
  <div class="panel panel-default">
    <div class="panel-heading">Panel heading<a href="/Referral/Create" class="btn btn-primary pull-right">Refer Me </a></div>
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Mark</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Jacob</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Larry</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

问题 为什么当我使用 "Pull-Right" 时 anchor 标记会脱离父级?

enter image description here

最佳答案

Clearfix 是一种处理 float 元素的过于复杂的旧方法。

您还需要为其添加条目到您的样式表。

但这是更现代和优雅的方法

.panel-heading {
    overflow:auto;
    }

这将强制浏览器计算适合 float 元素的高度。

这也有效:

.panel-heading {
    overflow:hidden;
    }

一些较旧的浏览器可能需要添加 width:100%width:auto 才能工作,但我已经很长时间没有遇到过这种情况了。

关于html - 如何将按钮 anchor 元素放置在父元素的最右边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874976/

相关文章:

html - 将标题 float 到两个不同的 div

html - h3 标签的垂直对齐中间不起作用

html - Bootstrap 布局 : getting two scrollbars

css - .visible-xs 不在 div 内居中

css - Angular Material 有网格系统吗?

javascript - parent 高度80%的 child (高度不详)

html - css3 rotate ul 在 Internet Explorer 中消失

jquery - 如何在申请下一个类之前等待 css 转换完成

javascript - 如何在 d3 条形图中左对齐刻度

javascript - 切换其他表行的可见性