twitter-bootstrap-3 - 表响应在引导程序 3 中不起作用
问题描述
我正在将 bootstrap 3 用于网站项目。我正在尝试创建一个带有响应式表格的页面,以便在表格太大时使用滚动条。我做了一个这样的测试用例:
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading main-color-bg">
<h3 class="panel-title">بازرسی انجام نشده</h3>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>کد درخواست</th>
<th>نام آموزشگاه</th>
<th>شماره ملی مؤسس</th>
<th>فعالیت گروه</th>
<th>شهرستان</th>
<th>نام و نام خانوادگی مؤسس</th>
<th>کد ملی</th>
<th>موبایل</th>
<th>شماره تماس آموزشگاه</th>
<th>آدرس</th>
<th>نمایش جزئیات</th>
</tr>
</thead>
<tbody>
@foreach($schools as $school)
<tr>
<td class="translate">{{ $school->id }}</td>
<td>{{ $school->school_name }}</td>
<td class="translate">{{ $school->national_number_founder }}</td>
<td>{{ $activity->group->group_name }}</td>
<td>{{ $school->cities->city_name }}</td>
<td>{{ $school->user->first_name }} {{ $school->user->last_name }}</td>
<td class="translate">{{ $school->user->national_code }}</td>
<td class="translate">{{ $school->user->mobile }}</td>
<td class="translate">{{ $school->phone }}</td>
<td>{{ $school->address }}</td>
<td>
<a href="{{ route('inspection-register.show', ['id' => $school->id]) }}"><span class="glyphicon glyphicon-list-alt"></span></a>
<a href="{{ route('schools-list.index') }}"><span class="glyphicon glyphicon-search"></span></a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
现在,问题是它没有添加滚动条,它只是将网站扩展到表格的宽度。
在此处查看屏幕截图:
我已经看到它在其他几个网站上运行,所以我正在做的事情......是错误的。
解决方案
使用您的代码创建了这支笔,您调整了窗口大小,滚动条会自动出现。我已按原样复制了您的代码,并添加了bootstrap-3
依赖项。
代码:
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading main-color-bg">
<h3 class="panel-title">بازرسی انجام نشده</h3>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>کد درخواست</th>
<th>نام آموزشگاه</th>
<th>شماره ملی مؤسس</th>
<th>فعالیت گروه</th>
<th>شهرستان</th>
<th>نام و نام خانوادگی مؤسس</th>
<th>کد ملی</th>
<th>موبایل</th>
<th>شماره تماس آموزشگاه</th>
<th>آدرس</th>
<th>نمایش جزئیات</th>
</tr>
</thead>
<tbody>
<tr>
<td class="translate">1</td>
<td>1</td>
<td class="translate">1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td class="translate">1</td>
<td class="translate">1</td>
<td class="translate">1</td>
<td>1</td>
<td>
<a href="{{ route('inspection-register.show', ['id' => $school->id]) }}"><span
class="glyphicon glyphicon-list-alt"></span></a>
<a href="{{ route('schools-list.index') }}"><span class="glyphicon glyphicon-search"></span></a>
</td>
</tr>
<tr>
<td class="translate">2</td>
<td>2</td>
<td class="translate">2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td class="translate">2</td>
<td class="translate">2</td>
<td class="translate">2</td>
<td>2</td>
<td>
<a href="{{ route('inspection-register.show', ['id' => $school->id]) }}"><span
class="glyphicon glyphicon-list-alt"></span></a>
<a href="{{ route('schools-list.index') }}"><span class="glyphicon glyphicon-search"></span></a>
</td>
</tr>
<tr>
<td class="translate">3</td>
<td>3</td>
<td class="translate">3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td class="translate">3</td>
<td class="translate">3</td>
<td class="translate">3</td>
<td>3</td>
<td>
<a href="{{ route('inspection-register.show', ['id' => $school->id]) }}"><span
class="glyphicon glyphicon-list-alt"></span></a>
<a href="{{ route('schools-list.index') }}"><span class="glyphicon glyphicon-search"></span></a>
</td>
</tr>
<tr>
<td class="translate">4</td>
<td>4</td>
<td class="translate">4</td>
<td>4</td>
<td>4</td>
<td>4</td>
<td class="translate">4</td>
<td class="translate">4</td>
<td class="translate">4</td>
<td>4</td>
<td>
<a href="{{ route('inspection-register.show', ['id' => $school->id]) }}"><span
class="glyphicon glyphicon-list-alt"></span></a>
<a href="{{ route('schools-list.index') }}"><span class="glyphicon glyphicon-search"></span></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</body>
</html>
添加overflow-x
将使其适用于所有布局
.table-responsive
{
overflow-x: auto;
}
推荐阅读
- r - 试图整合来自数据帧的离散点
- c# - 我可以使用 asp.net 身份发送密码重置电子邮件而不使用实体框架来管理我的用户吗?
- c - 什么定义了 C 中的 strscpy?
- mysql - 在条件连接中返回空值
- r - 使用 dplyr 根据列值对 R 中的值求和
- python - Python:向实例添加属性,让它出现在类中
- html - VSCode Emmet html样板?
- esp8266 - 如何为 ESP8266 实现 100 微秒的股票回调?
- bash - 使用 jq 从变量中更改 json 对象和字段值
- android - 扩展 MaterialButton 时,我无法检索在 styles.xml 中设置的自定义属性