use*_*953 2 css grid vertical-alignment twitter-bootstrap
假设我有以下HTML(好吧,haml,但是......):
.container
.row
.span4
%h1
%p
%img
.span4
%h1
%p
%img
.span4
%h1
%p
%img
Run Code Online (Sandbox Code Playgroud)
因此,每列都有一个标题,一些文本和一个图像.有没有办法让图像垂直对齐,就好像它们是这样做的:
.container
.row
.span4
%h1
%p
.span4
%h1
%p
.span4
%h1
%p
.row
.span4
%img
.span4
%img
.span4
%img
Run Code Online (Sandbox Code Playgroud)
但没有创建新行?原因是,我希望将图像与标题和文本分组,这样在移动/平板电脑布局上,图像的布局与它们匹配的内容相同,而在第二种情况下,您将得到三个文本组,然后三个图像.
我可以想到两种方法:
在任何情况下,img-outer在某些情况下可能不是必需的.
<div class="container">
<div class="row">
<div class="span4">
<h1></h1>
<p></p>
<div class="img-outer"><img src="" /></div>
</div>
<!-- ... -->
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果为文本元素 h1及p以上设置固定高度,则图像将对齐.
您还可以为其设置固定高度.span并使用绝对定位.这个如下所示:
.container .row [class*="span"] {
height: 100px;
padding-bottom: 150px;
position: relative;
}
.container .row [class*="span"] .img-outer{
height: 150px;
line-height: 150px;
vertical-align: middle;
position: absolute;
bottom: 0;
/* Take the whole width */
left: 0;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)
似乎工作,我没有足够的绝对定位知识,以保证结果是跨浏览器.
.container .row {
padding-bottom: 150px;
position: relative;
}
.container .row [class*="span"] .img-outer{
height: 150px;
line-height: 150px;
vertical-align: middle;
position: absolute;
bottom: 0;
/* Take the whole width */
width: 300px; /* .span4 width */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17736 次 |
| 最近记录: |