设置DIV高度等于另一个DIV [英] Set a DIV height equal with of another DIV
本文介绍了设置DIV高度等于另一个DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个DIV,分别是.sidebar
和.content
,我想将.sidebar
设置为与.content保持相同的高度.
I have two DIVs, .sidebar
and .content
and I want to set .sidebar
to keep the same height with the .content.
我尝试了以下操作:
$(".sidebar").css({'height':($(".content").height()+'px'});
$(".sidebar").height($(".content").height());
var highestCol = Math.max($('.sidebar').height(),$('.content').height());
$('.sidebar').height(highestCol);
这些都不起作用.对于.content
,我没有任何身高,因为它会根据内容而增加或减少.
None of these are working. For the .content
I don't have any height since will increase or decrease based on the content.
请帮助我.我今天必须整理一个网页,这个(简单的)事情让我头疼.
Please help me. I have to finish up a web page today and this (simple) thing is giving me headaches.
谢谢!
推荐答案
第一个示例不起作用的原因是由于拼写错误:
The reason your first example isn't working is because of a typo:
$(".sidebar").css({'height':($(".content").height()+'px'});
实际上应该是
$(".sidebar").css({'height':($(".content").height()+'px')});
.content选择器之前缺少尾括号.
you're missing a trailing bracket from before the .content selector.
这篇关于设置DIV高度等于另一个DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文