列行的垂直对齐假设你有使用Twitter的引导一两栏布局,在其中你想有相互垂直对齐的特定行:在引导网格
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css"/>
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2>Column 1</h2>
<p>Optional content of variable height.</p>
<p><strong>Align this vertically...</strong></p>
</div>
<div class="col-sm-6">
<h2>Column 2</h2>
<p><strong>...with this</strong></p>
</div>
</div>
</div>
垂直对齐对于表格布局是可行的,然而,Bootstrap列的尺寸和响应行为丢失:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css">
<div class="container">
<table class="row">
<thead>
<tr>
<th scope="col"><h2>Column 1</h2></th>
<th scope="col"><h2>Column 2</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td><p>Optional content of variable height.</p></td>
</tr>
<tr>
<td><strong>Align this vertically...</strong></td>
<td><strong>...with this</strong></td>
</tr>
</tbody>
</table>
</div>
另一种选择是拆分行,但是布局在较小的分辨率上以错误顺序折叠。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2>Column 1</h2>
</div>
<div class="col-sm-6">
<h2>Column 2</h2>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p>Optional content of variable height.</p>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<strong>Align this vertically...</strong>
</div>
<div class="col-sm-6">
<strong>...with this</strong>
</div>
</div>
</div>
你如何达到同样的效果,同时仍保持引导的列的行为?是使用表格布局的方式还是死胡同?如果不使用JavaScript来将行定位到计算出的偏移量,那么它是否可行?
编辑:我的目标是让行的顶部对齐,就像在表格布局中一样。
'这对准垂直...'将是高度可变的或固定的高度? –
您是否定义了身高?也许你可以告诉我们你的CSS。 –
@MuhammadUsman:要对齐的内容具有可变的高度。 –