简体   繁体   English

使用CSS使表行高度相同

[英]Using CSS to make table rows the same height

I'm building an app in AngularJS that gets product data and displays it on a page. 我正在AngularJS中构建一个应用程序,该应用程序获取产品数据并将其显示在页面上。 The only reason I mention Angular is because, due to the way ng-repeat works, I can't simply put my images into one row so they default to the same height - each 'product' has to be its own td , table , div or similar. 我提到Angular的唯一原因是,由于ng-repeat工作方式,我不能简单地将我的图片放到一行中,因此它们默认使用相同的高度-每个“产品”必须是自己的tdtablediv或类似。

Anyway, that won't make sense without explaining my code and the issues I'm having. 无论如何,如果不解释我的代码和遇到的问题,这将是没有意义的。 I have products being displayed in rows of three. 我的产品每三行显示一次。 They look like this: 他们看起来像这样:

表格行图片

As you can see, when the images are all the same height, everything works fine. 如您所见,当图像高度相同时,一切正常。 The issue is, not all of my images are the same height, nor will they ever be. 问题是,并非我的所有图像都具有相同的高度,也不会如此。 I'm looking for a solution that accommodates this. 我正在寻找适合这种情况的解决方案。

The Markup 标记

To avoid ugly <table> code I've put it all in a fiddle here: http://jsfiddle.net/qGu2V/6/ 为了避免难看的<table>代码,我在这里把它们都放在了一个小提琴中: http : //jsfiddle.net/qGu2V/6/

The // spacer images I've marked in the fiddle would (if I knew more about tables) make the searchImgContainer fill the height of the containing <td> . 我在小提琴中标记的// spacer图像将(如果我对表格有更多了解)将使searchImgContainer填充包含的<td>的高度。

The Question 问题

Any ideas on how I can achieve this? 关于如何实现此目标的任何想法? The goal is not only to make all image containers the same height, but also to vertically centre the image within the container (so there is equal white space above and below it). 目标不仅是使所有图像容器都具有相同的高度,而且还要使图像在容器内垂直居中(因此,其上方和下方都有相等的白色空间)。

I know I can do this with javascript/jquery, but I'm loading hundreds and thousands of products onto a (mobile, responsive) page and I feel like constantly checking the height of the neighbouring image would create a large page load. 我知道我可以使用javascript / jquery来做到这一点,但是我正在将成千上万的产品加载到(移动,响应式)页面上,并且我觉得不断检查相邻图像的高度会产生很大的页面负载。

Is this achievable or am I stuck with Javascript solutions? 这是可以实现的,还是我坚持使用Javascript解决方案?

Try this one.. Demo 试试这个.. 演示

.searchThumb{
    height:100px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM