IE8 隐藏内容后包装器的高度仍然相同

发布于 2025-01-01 04:50:15 字数 2085 浏览 0 评论 0原文

前言

我再次遇到了那些奇怪的 Internet Explorer 问题之一,我遇到了麻烦。 更准确地说,是IE8。我也在IE7中测试过,那里没有问题,所以IE8有问题..

注意,有一个 JSFiddle 示例位于本文底部,重现了我的问题。


快速解释

我已经得到了这个ul,它用于在以下情况下扩展/收缩内容:点击span.content_head。默认情况下,首先显示内容。

<div id="spreadsheet_overview">
    <ul class="overview_list">
        <li>
            <div class="content_head">
                <div class="indicator"></div>
                Recipe calculation
                <div class="summation">
                    <span class="title">1 tablet cost:</span>
                    <span class="value">0.09360828</span>
                </div>
            </div>
            <div class="container">Lots of content</div>
        </li>
    </ul>
</div>
$("div.content_head").click(function(e){
    $(this).next(".container").toggle();
    $("div.indicator",this).toggleClass("contracted");
});

问题

当我点击合同时出现问题。让我首先向您展示它在 Firefox 中的外观及其工作原理。

在此处输入图像描述
文档由

  • 正文组成——略深灰色的
  • 包装纸、亮灰色的
  • 分隔栏、深灰色的
  • 更多分隔线、白色。

如您所见,文档在“配方计算”后结束,文档的高度已调整并删除了垂直滚动条。
包装纸的高度也已调整。

然而,在 Internet Explorer 8 中,当我执行相同的操作时,包装器会保持其高度,就好像内容仍然显示一样。为什么IE不调整高度?

在此处输入图像描述

我已经检查过,高度与隐藏内容之前完全相同。

如果这是 CSS 问题(我确信是这样),那可能是什么?


JSFiddle

这是一个 JSFiddle 可以重现我的具体问题。我尝试将 CSS 减少到仅包含本期中的元素。
这可能是我用 CSS/HTML 完成的事情。
希望你们中的一个人能发现它,因为我肯定不能...

单击“配方计算”将隐藏内容,您会注意到高度仍然相同。在IE8中。

感谢您的帮助!

w3d编辑

指出,当在开发人员工具中切换 height: auto 属性时,将调整包装器高度。经过进一步调查,当我调整窗口大小时,它会做同样的事情。

Foreword

I've come across one of those weird Internet Explorer things again, and I've hit a wall.
To be more precise, it's IE8. I've also tested in IE7, and there is no problem there, so there's something with IE8..

Note that there is a JSFiddle example down the bottom of this post that reproduces my problem.


Quick explanation

I've got this ul that's being used to expand/contract content when clicking the span.content_head. By default, the content is first shown.

<div id="spreadsheet_overview">
    <ul class="overview_list">
        <li>
            <div class="content_head">
                <div class="indicator"></div>
                Recipe calculation
                <div class="summation">
                    <span class="title">1 tablet cost:</span>
                    <span class="value">0.09360828</span>
                </div>
            </div>
            <div class="container">Lots of content</div>
        </li>
    </ul>
</div>
$("div.content_head").click(function(e){
    $(this).next(".container").toggle();
    $("div.indicator",this).toggleClass("contracted");
});

The problem

The problem occur when I click to contract. Let me first show you how it looks in Firefox, where it works.

enter image description here
The document consists of

  • body - slightly dark gray
  • wrapper, bright gray
  • dividing column, dark gray
  • more dividers, white

As you can see, the document ends after "recipe calculation", and the height of the document has adjusted and removed the vertical scrollbars.
The wrapper has also adjusted its height.

In Internet Explorer 8, however, when I do the same thing, the wrapper maintain its height as if the content was still shown. Why isn't it adjusting the height in IE?

enter image description here

I've checked, and the height remains exactly the same as before I hid the content.

If this is a CSS issue, which I am sure it is, what could it be?


JSFiddle

Here's a JSFiddle that can reproduce my specific issue. I've tried to cut down the CSS enough to the elements only in this issue.
It's probably something I've done with the CSS/HTML.
Hopefully one of you can spot it, 'cause I sure as hell can't...

Clicking on "Recipe calculation" will hide the content, and you'll notice that the height is still the same. In IE8.

Appreciate the help!

Edits

w3d pointed out that when toggling the height: auto attribute in the developer tools, will adjust the wrapper height. After further investigation, it does the same thing when I resize the window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花肆意 2025-01-08 04:50:15

更改:

.fix{display: inline-block;}

至:

.fix{display: block;}

IE 不知道 inline-block 是什么。

Change:

.fix{display: inline-block;}

To:

.fix{display: block;}

IE doesn't know what inline-block is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文