【问题标题】:Z-index problem with absolute positioned element in IE7IE7中绝对定位元素的Z-index问题
【发布时间】:2011-11-21 02:47:56
【问题描述】:

我有一个带有代表用户当前状态的连接器 div 的 textarea。 connector-div 是绝对定位的,因此它与 textarea 一起形成了一个对话气泡,以象征用户正在“说”什么。连接器将被放置在 textarea 的“顶部”(通常是更高的 z-index),它在每个浏览器中都可以正常工作,但不幸的是我必须支持 IE7。在 IE7 中,connector-div 位于 textarea 下方,这就是问题所在。

我用谷歌搜索了 IE7 中 Z-index 错误的问题,并尝试了几种我找到的解决方案,但没有一个解决方案适合我的特殊情况。

我有以下简化的 html:

"

  <form class="current-status">
    <div class="talk-bubble">
      <div class="connector"> "Absolute positioned with high z-index.." </div>
      <textarea> "User status goes here" </textarea>
    </div>
  </form>

"

current-status-div 只是静态定位, talk-bubbble-div 是相对的, connector-div 是绝对的,z-index 为 4, textarea 是相对的,目前没有 z-index,因为它可以在除 ie7 之外的任何地方使用。 但我尝试在 texarea 上设置低 z-index 并在连接器上设置高,但 IE7 有奇怪的堆叠..

我尝试了很多不同的解决方案,包括定位、z 索引、包装元素等,但似乎没有任何效果。

有人有想法吗?

一些与问题相关的 css:

.content-box-plate {
    position: relative;
    z-index: auto;
}

.talk-bubble {
    position: relative;
    z-index: auto;
}

.connector {
    background: url("/images/portal/bubble_connector.png?1314369295") no-repeat scroll center center transparent;
    height: 12px;
    position: absolute;
    right: 5px;
    width: 21px;
    z-index: 4;
}
textarea {
    font-size: 13.5px;
    font-style: italic;
    height: 40px;
    line-height: 1.25em;
    overflow: auto;
    padding: 6px 6px 6px 8px;
    position: relative;
    width: 165px;
    z-index: auto (tried to put a specific value lower than connectors without effect)
}

【问题讨论】:

  • CSS 在哪里?问一个关于 CSS 的问题而不把它贴出来似乎很奇怪..
  • 如果你期待答案,你应该明确地添加你的 CSS,最好在JSFIDDLE做演示
  • 请提供指向您页面的链接,或jsFiddle/JS Bin 演示。明确一点:我想要一个可以使用 IE 开发者工具的现场演示。
  • ok 明天将添加与此相关的 css,不认为所有不相关的 css 规则(如边距、宽度等)都是必要的,所以我尝试包含相关的内容,但我明白了 :)

标签: html css internet-explorer-7 positioning z-index


【解决方案1】:

没有您的代码很难回答,但是您还需要在父 div 上设置 z-index,这是我在 IE6/7 中修复的常见问题,因为我也必须支持它们。

你可能不需要到表单上去,但是没有你的 CSS 并且看到它是很难说的 - 不过这个或附近会解决它!

您需要 position 有一个有效的 z-index,不要担心页面上的其他 z-index 等。因为这是封装在表单中;当然可以将值更改为您想要的任何值,但这就是排序。

<form class="current-status" style="position:relative; z-index:1;">
    <div class="talk-bubble" style="position:relative; z-index:1;">
      <div class="connector" style="position:absolute; z-index:2"> "Absolute positioned with high z-index.." </div>
      <textarea style="position:relative; z-index:1"> "User status goes here" </textarea>
    </div>
</form>

【讨论】:

  • 根据您的建议更改了定位和索引,并且 textarea 仍然位于 IE7 的连接器顶部,但在其他任何地方都可以使用(与大多数解决方案一样)。将不得不尝试找出解决方法..无论如何感谢您的建议!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多