我想创建这样的布局:
桌面
移动
但不知道如何实现这一目标。到目前为止,我有这个:
<aside class="container-fluid" role="complementary">
<div class="modal-container ">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-6 col-xs-12">
<h2>Name</h2>
<ul class="menu">
<li>Jack</li>
<li>John</li>
<li>James</li>
</ul>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-6 col-xs-12">
<h2>Surname</h2>
<ul class="menu">
<li>Sales</li>
<li>Admin</li>
<li>Sales</li>
</ul>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
<h2>Action</h2>
<a href="#" class="button">Connect</a>
<a href="#" class="button">Connect</a>
<a href="#" class="button">Connect</a>
</div>
</div>
<table>
<tr>
<td>Jack</td>
<td>Sales</td>
</tr>
<tr>
<td><a href="#" class="button">Connect</a></td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
</tr>
<tr>
<td><a href="#" class="button">Connect</a></td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
</tr>
<tr>
<td><a href="#" class="button">Connect</a></td>
</tr>
</table>
</div>
</aside>
&#13;
实现这些布局的最明智的方法是什么? (它应该与flex结合使用吗?可以使用BS网格吗?)
答案 0 :(得分:0)
这里总的引导网格理解是错误的。此外,我不想为您编写整个代码 - 请理解概念并实现移动布局。
下面是桌面的网格修正,您必须添加更多引导类才能使其更具响应性。
你不需要表格,你可以完全用BS完成这两种布局。
运行以下代码段,全屏打开并调整浏览器大小 - 您会注意到BS网格之美
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<aside class="container-fluid" role="complementary">
<div class="modal-container ">
<div class="row">
<div class="col-xs-12">
<h2 class='col-xs-4'> Name</h2>
<h2 class='col-xs-4'> Surname</h2>
<h2 class='col-xs-4'> Action</h2>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>Jack</span>
<span class='col-xs-4'>Sales</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>John</span>
<span class='col-xs-4'>Admin</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>James</span>
<span class='col-xs-4'>Sales</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
</div>
</div>
</aside>
&#13;
答案 1 :(得分:0)
在较小的屏幕上将<tr>
设置为 flexbox
@media (max-width: 575.98px) {
.my-table tr {
display: flex;
flex-wrap: wrap;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
看起来像是
body {
margin: 0;
}
header {
background: #00ADEE;
color: white;
height: 110px;
}
header h1 {
padding: 0.5rem;
margin: 0;
}
.my-table {
width: 50%;
margin-top: -50px;
margin-left: auto;
margin-right: auto;
background: white;
text-align: center;
border-collapse: separate;
border-spacing: 3rem 1.5rem;
border: 2px solid #E7E7E7;
}
.my-table th,
.my-table td {
padding: 0.5rem;
}
.my-table tr>td:last-child>a {
text-decoration: none;
display: block;
color: black;
padding: 0.5rem;
background: #E7E7E7;
}
@media (max-width: 575.98px) {
header h1 {
text-align: center
}
.my-table {
border-spacing: 1.5rem;
}
.my-table thead {
display: none;
}
.my-table tr {
display: flex;
flex-wrap: wrap;
text-align: center;
margin-bottom: 1.5rem;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
<header>
<h1>Table Test</h1>
</header>
<table class="my-table">
<thead>
<th>Name</th>
<th>Surname</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td>Jack</td>
<td>Sales</td>
<td><a href="">Connect</a></td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
<td><a href="">Connect</a></td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
<td><a href="">Connect</a></td>
</tr>
</tbody>
</table>
(根据您的需要更改值。)
中心表格offset
。使用与上面相同的概念。
body {
margin: 0;
}
header {
background: #00ADEE;
color: white;
height: 110px;
}
header h1 {
padding: 0.5rem;
margin: 0;
}
.my-table {
margin-top: -50px !important;
text-align: center;
background: white;
}
.my-table * {
border: none !important;
}
.my-table th {
text-align: center;
}
.my-table tr>td:last-child>a {
text-decoration: none;
display: block;
color: black;
background: #E7E7E7;
}
@media (max-width: 575.98px) {
header h1 {
text-align: center
}
.my-table thead {
display: none;
}
.my-table tr {
display: flex;
flex-wrap: wrap;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<header>
<h1>Table Test</h1>
</header>
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3">
<table class="my-table table">
<thead>
<th>Name</th>
<th>Surname</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td>Jack</td>
<td>Sales</td>
<td><a href="">Connect</a></td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
<td><a href="">Connect</a></td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
<td><a href="">Connect</a></td>
</tr>
</tbody>
</table>
</div>
</div>