html - 表格下的按钮对齐在CSS中不起作用
问题描述
我有这个 html 代码,其中我在容器内的 div 内有一个表。
<div class="col-sm-12">
<table class="table table-responsive table-bordered" id="calctable">
....
</table>
<button class="btn btn-suceess"></button>
</div>
我想直接在表格右下角移动按钮,类似于此。
我尝试了多种方法来获得我想要的东西,但它们不能正常工作。我尝试使用float-right
类将按钮浮动到右侧。我尝试使用col-sm-offset-11
. 也没有用。有没有办法解决这个问题?
解决方案
有几种方法可以实现您想要的,下面的两个示例在您的table
和button
元素周围使用了一个包装器:
.col-sm-12 {
background-color: red;
width: 300px;
padding: 10px;
margin-bottom: 10px;
}
.wrapper { width: 80%; }
table {
background-color: yellow;
height: 20px;
margin-bottom: 10px;
width: 100%;
}
/* With flexbox (don't forget to add vendor prefixes) */
#test-flex .wrapper {
display: flex;
flex-direction: column;
}
#test-flex button { align-self: flex-end; }
/* With float */
#test-float button { float: right; }
.clear { clear: both; }
<!-- With flexbox -->
<div id="test-flex" class="col-sm-12">
<div class="wrapper">
<table></table>
<button>Button</button>
</div>
</div>
<!-- With float -->
<div id="test-float" class="col-sm-12">
<div class="wrapper">
<table></table>
<button>Button</button>
</div>
<div class="clear"></div>
</div>
推荐阅读
- html - 防止儿童触发悬停
- angular - 即使调试器显示条件为真,如果未输入块
- azure - 如何清理未使用的 Azure 资源
- javascript - 如何为 react-testing-library 定义容器大小?
- android - 如何解释 Build.SERIAL 的“此字段始终设置为 Build#UNKNOWN”
- apache-kafka - kafka producer MetricName 中的 node-id 标签是什么,我如何从 KafkaProducer 实例中获取它?
- winforms - 如何在 PowerShell 中使用 button.add_click 函数更新或刷新组合框项目?
- python - 最后一行 #5 与 readomforest 分类器的分类有问题
- ios - RxSwift,如何使用 .code 返回错误?
- java - Java:使用滑块更改矩形沿路径的速度