[英]Make a flex class from Bootstrap 4 take full height of the table cell parent
I am using Bootstrap 4 CSS and JS (from the official CDN), along with Font Awesome 5 (also official CDN). 我正在使用Bootstrap 4 CSS和JS(来自官方CDN)以及Font Awesome 5(也是CDN)。
I was originally using the text-center
class from Bootstrap, since FA5 icons are just text. 我最初使用的是Bootstrap中的text-center
类,因为FA5图标只是文本。 Then I tried using text-justify
to make the icons dispersed better on larger-width displays, but this didn't work at all. 然后,我尝试使用text-justify
使图标在较大宽度的显示器上更好地分散,但这根本不起作用。
Here is the table cell part of the markup. 这是标记的表格单元格部分。 I didn't want to paste the whole thing here because the templating (Jinja2) is fairly long. 我不想将整个内容粘贴到这里,因为模板(Jinja2)相当长。
<td>
<div class="container-fluid d-flex justify-content-between">
<i class="fas fa-fw fa-chevron-up"></i>
<i class="fas fa-fw fa-chevron-down"></i>
<i class="fas fa-fw fa-star"></i>
</div>
</td>
Table cell displays as expected except it is not full height and the icons look off-center. 表格单元格按预期显示,除了不是全高而且图标看起来偏离中心。
Does anyone have a fairly simple way to make the d-flex
element use the full height of the parent cell? 有没有人有一个相当简单的方法来使d-flex
元素使用父细胞的整个高度? Or just a better way in general to make up-vote, down-vote, and favorite icons fit well within a table cell? 还是一般来说,使上投票,下投票和喜欢的图标很好地适合表格单元的更好方法? I also need to figure out a way to make the current scores / favorites number align well with all of the other cells in the table. 我还需要找出一种方法,使当前分数/收藏夹数字与表格中的所有其他单元格保持一致。 Any existing solutions or advice you have would be very helpful as well. 您现有的任何解决方案或建议也将非常有帮助。
Edit: As an afterthought, I should add that these icons will eventually be inside of buttons if that makes a difference. 编辑:事后,我应该补充说,如果有所不同,这些图标最终将位于按钮内。
Thanks. 谢谢。
Use align-items-center bootstrap class to align your elements center of the cell. 使用align-items-center bootstrap类将元素的单元格中心对齐。 If you used any custom line-height, Kindly remove it. 如果您使用了任何自定义行高,请删除它。
<td>
<div class="container-fluid d-flex justify-content-between align-items-center">
<i class="fas fa-fw fa-chevron-up"></i>
<i class="fas fa-fw fa-chevron-down"></i>
<i class="fas fa-fw fa-star"></i>
</div>
</td>
Note: The question was not clear to me. 注意:这个问题我不清楚。 I gave the solution to align your fa icons vertically center to the cells. 我给出了将fa图标垂直对齐到单元格的解决方案。 Hope u asking the same... 希望你问同样的...
You say the icons will eventually be inside of buttons. 您说图标最终将在按钮内。 Why not use a button group? 为什么不使用按钮组? Or use bootstraps col classes to align things. 或使用bootstrap col类来对齐内容。 Set the height of the button 100% to take up the full height of the cell. 将按钮的高度设置为100%,以占据单元格的整个高度。 Both ideas shown below. 这两个想法如下所示。
I hope this helps 我希望这有帮助
td{ height: 100px; } .btn, .btn-group{ height: 100%; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/> <table> <tbody> <tr> <td> <div> <span class="col-sm-4"> <i class="fas fa-fw fa-chevron-up"></i> </span> <span class="col-sm-4"> <i class="fas fa-fw fa-chevron-down"></i> </span> <span class="col-sm-4"> <i class="fas fa-fw fa-star"></i> </span> </div> </td> </tr> <tr> <td> <div class="btn-group" role="group" aria-label="Basic example"> <button type="button" class="btn btn-light"> <i class="fas fa-fw fa-chevron-up"></i> </button> <button type="button" class="btn btn-light"> <i class="fas fa-fw fa-chevron-down"></i> </button> <button type="button" class="btn btn-light"> <i class="fas fa-fw fa-star"></i> </button> </div> </td> </tr> </tbody> </table> <script defer src="https://use.fontawesome.com/releases/v5.0.2/js/all.js"></script> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
Why using .container-fluid
with .d-flex
? 为什么将.container-fluid
与.d-flex
? Use another parent tag for container-fluid class. 对容器流体类使用另一个父标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.