我有以下Html / Bootstrap 4代码块
<div class="col-xs-12 col-md-4">
<div class="panel-group" id="panel-790692">
<th:block th:each="state : ${stateIterable}">
<div class="panel panel-default">
<div class="panel-heading">
<a class="panel-title" data-toggle="collapse"
data-parent="#panel-790692"
th:href="|#panel-element-${#strings.replace(state.state,' ','-')}|"
th:text="${state.state}">State Name</a>
</div>
<div
th:id="|panel-element-${#strings.replace(state.state,' ','-')}|"
class="panel-collapse collapse in">
<th:block th:each="city : ${state.cities}">
<div class="panel-body" th:text="${city.city}"></div>
</th:block>
</div>
</div>
</th:block>
</div>
</div>
现在所有州都显示为一个长垂直列,我怎样才能使这个响应?我希望它在桌面上有3或4列,在移动设备上有一列。
这是小提琴
答案 0 :(得分:1)
将col-md-3
添加到panel panel-default
类
body {
margin: 10px;
}
&#13;
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container" style="padding-top: 200px; padding-bottom: 100px;">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="panel-group" id="panel-790692">
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Alabama">Alabama</a> </div>
<div class="panel-collapse collapse in col-md-3" id="panel-element-Alabama">
<div class="panel-body">Auburn</div>
<div class="panel-body">Birmingham</div>
<div class="panel-body">Dothan</div>
<div class="panel-body">Gadsden</div>
<div class="panel-body">Huntsville</div>
<div class="panel-body">Mobile</div>
<div class="panel-body">Montgomery</div>
<div class="panel-body">Muscle Shoals</div>
<div class="panel-body">Tuscaloosa</div>
</div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Alaska">Alaska</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Alaska">
<div class="panel-body">Anchorage</div>
<div class="panel-body">Fairbanks</div>
<div class="panel-body">Juneau</div>
<div class="panel-body">Kenai Peninsula</div>
</div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Arizona">Arizona</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Arizona"> </div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Arkansas">Arkansas</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Alaska">
<div class="panel-body">Anchorage</div>
<div class="panel-body">Fairbanks</div>
<div class="panel-body">Juneau</div>
<div class="panel-body">Kenai Peninsula</div>
</div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-California">California</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Alaska">
<div class="panel-body">Anchorage</div>
<div class="panel-body">Fairbanks</div>
<div class="panel-body">Juneau</div>
<div class="panel-body">Kenai Peninsula</div>
</div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Colorado">Colorado</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Alaska">
<div class="panel-body">Anchorage</div>
<div class="panel-body">Fairbanks</div>
<div class="panel-body">Juneau</div>
<div class="panel-body">Kenai Peninsula</div>
</div>
</div>
<div class="panel panel-default col-md-3">
<div class="panel-heading"> <a class="panel-title" data-toggle="collapse" data-parent="#panel-790692" href="#panel-element-Connecticut">Connecticut</a> </div>
<div class="panel-collapse collapse in" id="panel-element-Alaska">
<div class="panel-body">Anchorage</div>
<div class="panel-body">Fairbanks</div>
<div class="panel-body">Juneau</div>
<div class="panel-body">Kenai Peninsula</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end container -->
</div>
&#13;