本文介绍了设置两个元素的高度以使其彼此匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


我想编写一个函数,给出两个元素将使他们的

高度等于更大的元素。我已经去了它并且它有效,

但它使它们的高度都比它们中的任何一个都大(但是相等)


代码如下:


var newheight =(second.offsetHeight> first.offsetHeight)?

second.offsetHeight:

first.offsetHeight;


first.style.height = newheight +" px";

second.style.height = newheight +" px" ;;

所以,我显然做了一些愚蠢的事情,但是有人可以启发我吗?

我试着写一下offsetHeight但是这些改变似乎被忽略了。


干杯,

Andy


Hi all,

I want to write a function that given two elements will make their
heights equal to the larger element. I''ve had a go at it and it works,
but it makes both their heights larger than either of them (but equal)

The code is as follows:

var newheight = (second.offsetHeight > first.offsetHeight) ?
second.offsetHeight :
first.offsetHeight;

first.style.height = newheight + "px";
second.style.height = newheight + "px";
So, I''m obviously doing something stupid, but can anyone enlighten me?
I tried writing to offsetHeight but the changes seemed to be ignored.

Cheers,
Andy

推荐答案





尝试:alert(second.offsetHeight); alert(first.offsetHeigh t); alert(newheight)


Try: alert(second.offsetHeight);alert(first.offsetHeigh t);alert(newheight)




好​​的,我明白了:


123

153

153


如果我在之后发出相同的警报:


first.style.height = newheight +" px";

second.style.height = newheight +" px";


我得到:


162

162

153


所以,那是我的问题。它们现在的高度相同但是我的查询

表示它们都比以前更大。


干杯,

Andy



OK, I get:

123
153
153

If I put the same alerts in after:

first.style.height = newheight + "px";
second.style.height = newheight + "px";

I get:

162
162
153

So, that''s my problem. They are now equal in height but as my query
said it makes both of them larger than either was before.

Cheers,
Andy





问这个在一个CSS论坛中,我相信他们会有办法做到这一点(或者至少让它看起来像是在发生这种情况),而不需要任何脚本。


尝试:


comp.infosystems。

-

Rob



Asking this in a CSS forum, I''m sure they''ll have a way to do this (or
at least make it look like it''s happening) without any scripting.

Try:

comp.infosystems.www.authoring.stylesheets
--
Rob


这篇关于设置两个元素的高度以使其彼此匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:46