当我添加时
.caption h4 {
min-height: 2.2em; /* 2 lines as line-height is 1.1 */
}
我在同一级别获得所有“查看详细信息”。但是,这显然不能解决字幕更高的问题。它仅在实际上没有更高的标题时才有效。 (但没关系,如果你确定没有什么会比你的倍数更高。)
所以,我改为应用这一点 CSS 来从另一侧设置限制。
.caption h4 {
max-height: 4.4em; /* 4 lines as line-height is 1.1 */
height: 4.4em; /* making it a multiple allows usage of overflow */
overflow: hidden; /* without cutting a line in the middle */
}
如果你想动态地设置一个最大高度等于最高字幕的高度,那么你将不得不使用一点点JS:
(function(d) {
var captions = d.querySelectorAll('.caption h4'),
height = 0;
for(var i = 0; i < captions.length; i++) {
height = Math.max(height, captions[i].offsetHeight); // or clientHeight depends on you box model
}
var style = d.createElement('style');
style.type = 'text/css';
style.innerHTML = '.caption h4 { max-height: '+ height +'px; height: '+ height +'px; }'; // they don't need overflow as none of them can overflow;
d.getElementsByTagName('head')[0].appendChild(style);
})(document);
您将此脚本添加到正文的末尾,以便 DOM 已经加载(或以某种方式在加载时触发它)。
重要提示:由于querySelectorAll,旧版浏览器不支持此sn-p。
当我在您的网站上运行它时,这就是诀窍。