gpt4 book ai didi

html - Bootstrap 4 : Vertical alignment in responsive table

转载 作者:行者123 更新时间:2023-11-28 02:36:41 25 4
gpt4 key购买 nike

使用 Bootstrap 4,当 table-responsive 添加到表格时,文本不再垂直居中。这是一个错误吗?如果没有,是否有一个简单的解决方案可以使文本居中居中。纯 Bootstrap 解决方案将不胜感激。

这是问题的说明。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> 

<table class="bg-danger table-responsive" style="width:300px; height:200px;">
<tr>
<th scope="row">
<div class="text-left">
table-responsive
</div>
</th>
</tr>
</table>

<table class="bg-success " style="width:300px; height:200px;">
<tr>
<th scope="row">
<div class="text-left">
no table-responsive
</div>
</th>
</tr>
</table>

最佳答案

您必须将 .table-responsive 类添加到容器元素,而不是表格本身。

Docs

Responsive tables allow tables to be scrolled horizontally with ease. Make any table responsive across all viewports by wrapping a .table with .table-responsive. Or, pick a maximum breakpoint with which to have a responsive table up to by using .table-responsive{-sm|-md|-lg|-xl}.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>

<div class="table-responsive">
<table class="bg-danger" style="width:300px; height:200px;">
<tr>
<th scope="row">
<div class="text-left">
table-responsive
</div>
</th>
</tr>
</table>
</div>
<table class="bg-success " style="width:300px; height:200px;">
<tr>
<th scope="row">
<div class="text-left">
no table-responsive
</div>
</th>
</tr>
</table>

关于html - Bootstrap 4 : Vertical alignment in responsive table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46835586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com