通过 CSS 重置 HTML 元素的高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/212534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:32:20  来源:igfitidea点击:

Resetting height of an HTML element via CSS

asp.nethtmlcss

提问by Kon

I use a custom-built asp.net control that renders to a DIV and has "height='0'" hard-coded into the element (I know.. stupid). But I need to reset it - get rid of the height assignment somehow. Is this doable with CSS?

我使用自定义构建的 asp.net 控件呈现到 DIV 并将“height='0'”硬编码到元素中(我知道..愚蠢)。但我需要重置它 - 以某种方式摆脱高度分配。这对CSS可行吗?

I can set the height to 100px for example, and it works. But that's not what I want - I want the height assignment removed pretty much.

例如,我可以将高度设置为 100px,它可以工作。但这不是我想要的 - 我希望高度分配几乎被删除。

UPDATE: Using FireBug, I can see that CSS's height gets overridden by the hard-coded one:

更新:使用 FireBug,我可以看到 CSS 的高度被硬编码的高度覆盖:

removed dead ImageShack link

删除了无效的 ImageShack 链接

I guess there's no way for me to resolve this besides removing the hard-coded height=0. Anyone else see an alternative?

我想除了删除硬编码的 height=0 之外,我没有办法解决这个问题。还有其他人看到替代方案吗?

回答by Oli

You might well need to use height:auto !importantbecause the height attribute has a very high priority (IIRC).

您可能需要使用,height:auto !important因为 height 属性具有非常高的优先级 (IIRC)。

But ideally you would karate-kick that attribute out of there. Yuck.

但理想情况下,您会空手道踢出该属性。哎呀。

回答by Keith Twombley

change the height to 'auto' and see if that works for you.

将高度更改为“自动”,看看是否适合您。

Auto is the default height for elements, it means the browser calculates the height itself.

Auto 是元素的默认高度,这意味着浏览器会自行计算高度。

回答by Rahul

The style attribute always overrides class. So you're going to have to remove the height rule of the style attribute.

样式属性始终覆盖类。因此,您将不得不删除样式属性的高度规则。