简体   繁体   English

div在IE7中消失

[英]div disappearing in IE7

I have a problem with a div in IE7, it's disappearing and I don't understand why.我在 IE7 中有一个 div 的问题,它正在消失,我不明白为什么。 I already tried to add zoom:1 and overflow: hidden as someone suggested but it is not working.我已经尝试添加 zoom:1 和 overflow: hidden 正如有人建议的那样,但它不起作用。

The div is inside an unordered list (floated left) as the last element, floated right. div 在无序列表(向左浮动)中作为最后一个元素,向右浮动。

This is the HTML这是 HTML

<div id="top_menu">
    <ul id="dropmenu">
        <li>menu item1</li>
        <li>menu item2</li>
        ...
     </ul>
    <div class="lang">content</div>
</div><!-- end top menu -->

This is the CSS这是 CSS

  #top_menu                     {width:900px;font-size:13px; }
    #top_menu ul#dropmenu           {width:630px; height:28px; margin:0px; padding:0px; list-style:none; float:left; }
    #top_menu ul#dropmenu li        {float:left;display:block;}
    .clearfix                       {display: inline-block;}  /* for IE/Mac */

    #top_menu .lang { width: 120px; color:#fff; margin:4px 10px 0 0; float: right; }
    #top_menu .lang a{ color:#ff8601; }
    #top_menu .lang a:hover{ color:#fff; }

Thanks for your help谢谢你的帮助

EDIT: I included the html and removed url to avoid client complaints.编辑:我包括了 html 并删除了 url 以避免客户投诉。

You need to add .clearfix to div#top_menu and add height: 24px;您需要将.clearfix添加到div#top_menu并添加height: 24px; to div.langdiv.lang

That fixed all the menu problems for me.这为我解决了所有菜单问题。

edit编辑

...and probably don't use absolute positioning to solve layout issues. ...并且可能不使用绝对定位来解决布局问题。

i'm on IE9 now, but putting this site into "Compatibility View" seems to show the issue too.我现在在 IE9 上,但是把这个网站放到“兼容性视图”中似乎也显示了这个问题。

The last entry in the main menu [ul] seems to extend all the way to the right of the element.主菜单中的最后一个条目 [ul] 似乎一直延伸到元素的右侧。 This appears in markup before the.lang div so I wouldn't expect it to be covering it up...这出现在 .lang div 之前的标记中,所以我不希望它会覆盖它......

Have you maybe tried putting the.lang element into "position:absolute" and then seeing if it shows up, (obviously assuming the parent element of it is positioned relatively).您是否尝试过将 .lang 元素放入“位置:绝对”,然后查看它是否显示出来(显然假设它的父元素是相对定位的)。 After that maybe try absolute with a top of 20px or so and see if it shows up then.在那之后,可以尝试绝对的 20px 左右的顶部,看看它是否会出现。

Good Luck!祝你好运!

UPDATE更新

Hang on a tick there.挂在那里。 your.lang div is inside the [ul] element so is actually incorrectly positioned, since the only element allowed as a child of a [ul] is a [li]. your.lang div 在 [ul] 元素内,因此实际上定位不正确,因为唯一允许作为 [ul] 子元素的元素是 [li]。

Why not try taking this div out of the list and have it instead, just outside, as a child of the #top_menu element....?为什么不尝试将此 div 从列表中取出,并将其作为#top_menu 元素的子元素放在外面......?

That might work!那可能行得通!

Not sure if this is relevant to your situation, but some versions of IE will throw away empty divs;不确定这是否与您的情况有关,但某些版本的 IE 会丢弃空 div; if the div doesn't contain anything, adding something like &nbsp;如果 div 不包含任何内容,请添加类似 &nbsp; 的内容will force it to exist.将迫使它存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM