[英]CSS set similar items to the same height as the tallest item on screen
[英]Make all list items same height as the tallest
我正在創建一個測驗,每個問題輸出4個列表項,每個問題的答案高度不同...
我想編寫一個腳本,該腳本運行並將所有div設置為與最大div相同的高度...
僅當我的答案包含圖像時,才具有以下內容:它在圖像加載完成之前先計算hiehgt,然后將高度設置為相當高的錯誤,有人可以看到我寫此圖像的更好方法嗎?
function resizeAnswers(){
var maxHeight = 23;
$('.text-answers li').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.text-answers li').each(function() {
$(this).height(maxHeight);
});
}
要等待所有圖像加載完畢,請在窗口加載完成后調用您的代碼:
$(window).load(function() {
resizeAnswers();
});
請注意,這將等待所有圖像加載,這可能是一個問題,具體取決於站點的性質。 如果有問題,您可以等待列表項中的圖像加載,但這更加復雜。
另外,您有:
$('.text-answers li').each(function() {
$(this).height(maxHeight);
});
但這將做完全相同的事情:
$('.text-answers li').height(maxHeight);
jQuery將愉快地將大多數操作應用於一組元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.