2013-08-07 54 views
0

我試圖顯示兩個div的高度設置爲第三個身體寬度,並匹配這些高度,如果divs需要更多的空間來匹配一個。像高度相等的柱子。jQuery列等於高度問題

這是我到目前爲止有:

var width = $('body').width(); 
var thirtyheight = width /10*3 
$('.thirtyheight').css('height',thirtyheight); 

這得到寬度和集作爲高度完美,我一直在使用等高片段與此無關,但尚未有合作嘗試。

如果有人有任何建議,我很樂意聽到他們。

回答

0

檢查此

$('.thirtyheight').css({'height',thirtyheight+'px'}); 
0

首先計算出主體高度的1/3,並將其保存在變量中。然後去掉每列,並檢查它是否高於計算的高度,如果yes覆蓋之前保存的變量。事情是這樣的:

var c = $("body").height()/100 * 33.33; 
$(".thirtyheight").each(function(index, el) { 
    if ($(el).height() > c) { c = $(el).height(); } 
}).height(c); 

工作小提琴:http://jsfiddle.net/3JdYj/

0

想通了,我已經決定讓家長高度來調整孩子的div,作品一種享受。

var colHeight = $(".parent").height(); 
$('.child').css('min-height',colHeight);