html - CSS:如何将按钮位置设置在html表格的右侧

标签 html css

我有一个 html 表,其列是通过 Ajax 调用和 Jquery 动态生成的。因此表格的宽度不是固定的。

我想在表格的顶部和底部设置仅与表格宽度右对齐的按钮。

如果我只执行 float: right; -> 我的按钮将对齐到页面的最右侧。

如果我执行 margin: 40px 0 0 620px; -> 我的按钮将以特定宽度对齐到特定表格的右侧。

但这不是我的目标。

目前我的 CSS 看起来像这样:

// Button at the top of the table //
.BackBtn
{
    margin: 40px 0 0 620px;
    float:right;
    position:relative;
}

// Table itself //
table {
    border:none;
    margin: 10px 0 0 20px;
    border-collapse:collapse;
}

// Confirm button //
.button{
   padding:25px 500px 0 950px;  
   width:240px;
}

https://jsfiddle.net/ama3123d/3/

jsfiddle 不显示任何表,因为该表是通过对 web 方法的 Ajax 调用动态创建的,然后 jquery 解析信息并创建列并填充值。

最佳答案

一个简化的解决方案是,使设置为 display: inline-block; 的包装器元素与包含的表一样宽。现在您可以设置 text-align: right; 来水平对齐按钮元素。要将其应用于您的特定案例,您必须通过生成的表格示例向我们提供您的确切标记。

table,
td {
  border: 1px solid;
  padding: 10px;
}

.wrapper {
  display: inline-block;
  text-align: right;
}
<div class="wrapper">
  <button>top</button>
  <table>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>
  <button>bottom</button>
</div>

关于html - CSS:如何将按钮位置设置在html表格的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46203331/

相关文章:

javascript - 使用 ng-repeat 从 2 个不同的 JSON 文件中提取数据

html - 我如何拍摄一个圆圈的 SVG 图像并将其放在网页的底部,以一种您始终只能看到上半部分的方式

html - 事件单元格的边界不应延伸到相邻单元格

html - 匹配网页上不同元素的宽度。 HTML IE7 和 IE8

javascript - 如何使叠加效果与图像响应

html - 导入 font-awesome 导致 Chrome Mobile 上的 x 轴溢出

javascript - 如何滚动到我的按钮? .scrollTo() 不起作用

html - 无法使用多个媒体查询

html - 如果 ul 元素包含 li 元素,如何将 css 应用于外部 div

javascript - Swiper slider 鼠标滚动和循环内容