如何使用 jQuery 从 DIV 中删除高度样式? [英] How do I remove the height style from a DIV using jQuery?

查看:29
本文介绍了如何使用 jQuery 从 DIV 中删除高度样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,DIV 的高度由其内容决定.

By default, a DIV's height is determined by its contents.

但是,我覆盖了它并使用 jQuery 显式设置了高度:

But, I override that and explicitly set a height with jQuery:

$('div#someDiv').height(someNumberOfPixels);

我怎样才能扭转这种局面?我想删除高度样式并使其恢复到自动/自然高度?

How can I reverse that? I want to remove the height style and to make it go back to it's automatic/natural height?

推荐答案

去除高度:

$('div#someDiv').css('height', '');
$('div#someDiv').css('height', null);

就像约翰指出的那样,将高度设置为auto:

like John pointed out, set height to auto:

$('div#someDiv').css('height', 'auto');

(使用 jQuery 1.4 检查)

(checked with jQuery 1.4)

这篇关于如何使用 jQuery 从 DIV 中删除高度样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆