css - 为什么负边距在 IE 7 中不起作用?

标签 css internet-explorer internet-explorer-7

我在链接上声明了负边距,但它在 IE 7 上不起作用。

#search a {
    color: #E5E5E5;
    text-decoration: none;
    font-weight: bold;
    float:right;
    margin-top:-20px; // this is not working on ie, only mozilla
}

有解决办法吗?

最佳答案

{position: relative;} 可能是必需的,如前所述,但您可能还有另一个问题:

通常,如果使用负边距技术将元素突出到其父容器之外,IE7 将不会绘制元素突出到其父容器之外的部分(尽管它会尊重其他影响突出的方法,例如 {溢出:可见}).

这是一个与“hasLayout”相关的 IE 错误 ,可以在“Has Layout: Negative Margin Bug 中找到对其的彻底处理。

正如上面引用的引用注释,有一些方法可以诱使 IE7 绘制元素的具有负边距的部分,该部分突出到其父元素之外,但它涉及“......不使用任何提供元素布局的属性”这可能会限制您想要使用的其他设计技术,并且会产生其他副作用(同样,请参阅引用的引用资料)。

但要回答您的问题:解决方法请参见 the list of properties that induce "hasLayout" ,(比如位置、高度和宽度——哎呀!)并确保它们都没有应用于您的容器。

关于css - 为什么负边距在 IE 7 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5541772/

相关文章:

jquery - 不工作 : remove style attribute or change width\height css property via jquery in IE6\IE7\IE8

css - 单选按钮在 IE7 中显示不正确,但在 Firefox 中正常?

html - 如何针对 ie7 标准定位 css

css - 什么会影响 width 属性的可用性?

c++ - 如何使用 C++ 和 WinAPI 检查 Web 浏览器是否正在运行?

.net - 使用默认用户代理请求浏览器返回 InternetExplorer 而不是 IE

jquery - 我怎样才能说服 IE 只显示 application/json 而不是提供下载呢?

html - 修改两个div之间的间距

html - 未应用 ListView CSS 类

css - 在 div 悬停时为 div 内的元素设置样式