[英]How to align elements with different height to the top AND to the bottom in table cells?
I'm working on a Drupal site that promotes rural products and services of several vendors. 我正在一个Drupal网站上工作,该网站推广了多家供应商的农村产品和服务。 On the main page I display a few items in a grid, each on a 'product card' (vendor, address, phone, product image, product name, price, 'Buy now' button).
在主页上,我在网格中显示一些项目,每个项目都在“产品卡”上(供应商,地址,电话,产品图片,产品名称,价格,“立即购买”按钮)。 Since each part of these attributes of a product may has different lenght, the layout of the page is very confused (see this screenshot: http://tinypic.com/r/2i1ede9/5 ).
由于产品的这些属性的每个部分可能具有不同的长度,因此页面的布局非常混乱(请参见此屏幕快照: http : //tinypic.com/r/2i1ede9/5 )。
Actually I have two questions about this issue: 其实我对此有两个问题:
display: inline-block;
display: inline-block;
and the vertical-align: top;
the vertical-align: top;
or vertical-align: bottom;
vertical-align: bottom;
attributes but they didn't worked for me. Drupal generates the grid with these table cells and divs: Drupal使用这些表单元格和div生成网格:
<tr class="row-3 row-last">
<td class="col-1 col-first">
<td class="col-2">
<div class="vm_prod_cat prod_cat_tur">
<div>
<div class="views-field views-field-uc-product-image">
<div class="vm_product">
<div class="offsite_selling">
</td>
<td class="col-3 col-last">
</tr>
You could use the display:table family rules to have boxes behaving like tables : 您可以使用display:table家庭规则来使框的行为类似于table:
.gal {
width:80%;
margin:auto;
text-align:center;
min-width:350px;
}
.gal article {
display:inline-table;
height:300px;
width:30%;
min-width:100px;
box-shadow: 0.5em 0.5em 0.5em,
inset 0 0 0 1px;;
margin:10px;
}
.gal article > header ,
.gal article > footer ,
.gal article > div {
display:table-row;
padding:0.5em;
background:gray
}
.gal article > div {
display:table-cell;
height:100%;
vertical-align:middle;
background:rgba(0,0,0,0.2);
}
<section class="gal">
<article>
<header>
header that takes room it needs
</header>
<div>
content that takes room left
</div>
<footer>
footer that takes room needed
</footer>
</article>
<!-- ... and so on -->
see test here : http://codepen.io/gc-nomade/pen/ALifh 参见此处的测试: http : //codepen.io/gc-nomade/pen/ALifh
each article may grow alone. 每篇文章可能会单独增长。 To avoid them to grow on their width, add
table-layout:fixed;
为了避免它们的宽度增加,请添加
table-layout:fixed;
, nothing will stop them growing on their height. ,没有什么能阻止他们成长。 You need to set a minimal safe height.
您需要设置一个最小的安全高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.