如何阻止 Internet Explorer 的专有梯度过滤器切断应溢出的内容?
我在 CSS 中使用 Internet Explorer 渐变过滤器。
一切都很顺利,直到我注意到应该超出容器范围的图像 overflow:visible;
被剪裁,就好像容器被设置为 overflow:hidden;
我不知道为什么会发生这种情况,也不知道如何解决它。有人可以帮忙吗?
我在 IE8 和 IE7 中查看它,
这是导致问题的 css,当我将其注释掉时,不再有错误:
.box{
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#b4cfe9', endColorstr='#e4eefc'); /* IE6 & IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#b4cfe9', endColorstr='#e4eefc')"; /* IE8 */
}
I'm using the internet explorer gradient filter in my CSS.
It was all going well until I noticed that images that are supposed to extend beyond their containers overflow:visible;
are getting clipped as though the container was set to overflow:hidden;
I have no idea why this would happen, or how to fix it. Can anyone help?
I'm looking at it in IE8 and IE7
This is the css causing the issue, when I comment it out, no more bug:
.box{
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#b4cfe9', endColorstr='#e4eefc'); /* IE6 & IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#b4cfe9', endColorstr='#e4eefc')"; /* IE8 */
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是可行的,尽管它是额外的标记。
这种策略有一个好处,因为您可以添加多个渐变框并将它们的高度/宽度设置为父级的百分比,从而模拟 safari/moz 中允许的“颜色停止”行为。
例如:
This works, although it's extra markup.
There is a bonus to this tactic, as you can add multiple gradient boxes and set their heights/widths as a % of the parent, thus emulating the "colour stop" behaviour allowed in safari/moz.
For example:
我知道这并不能特别回答您的问题,但请考虑一下您的听众。他们只是 Internet Explorer 用户,还是代表了自然的互联网用户比例?如果他们不只是 IE 用户(可能在企业/教育网络中),那么请考虑仅使用符合标准的方法,并允许应用程序/站点正常降级到不支持它的浏览器(例如 IE)。
现在,回答你的问题。它没有按预期工作的原因是该框没有延伸到内容的末尾,即使溢出可见。内容只是“行走”到盒子外面,但这并不会使盒子变大。除非不设置固定的宽度和/或高度属性,否则无法让框扩展以适合内容。事实上,IE 有一个错误,该框没有溢出,而是扩展了(这是一个错误)。
不过我可以推荐一个技巧;使用min-<宽度/高度>和max-<宽度/高度>代替宽度和/或高度< /em>。它们允许您灵活调整盒子大小,并带有引导边界。
I know this doesn't answer your question in particular, but consider your audience. Are they all just Internet Explorer users, or do they represent natural internet user proportions? If they are not all just IE users (maybe in a corporate/education network) then consider using only the standards-compliant methods, and allowing the application/site to degrade gracefully to a browser that doesn't support it, like IE.
Now, for your question. The reason why it's not working as you expected is that the box does not extend to the end of content, even when overflow is visible. The content simply 'walks' outside the box, but this doesn't make the box bigger. There is no way you can get the box to extend to fit the content, except for not setting the width and/or height properties fixed. In fact, IE had a bug in which instead of overflowing out, the box did extend (this was a bug).
I can recommend one tip though; use min-<width/height> and max-<width/height> instead of width and/or height. They allow you flexible box sizing, with guided boundaries.
我将父 div 的位置设置为相对位置并且它有效:)(或绝对位置,也工作得很好)
I set parent div's position to relative and it worked :) (or absolute, works fine too)
这可能会对那些选择放弃 IE7 支持的人有所帮助。
如果元素被定位(相对/绝对/固定),IE7 总是会出现问题。在 IE8+ 中,如果将 z-index 设置为 auto,问题就会消失。
如果您需要支持 IE7,或者需要使用 z-index 堆叠内容,则必须采用第二个包装 DIV。
编辑2012-05-29:我创建了一个示例来展示如何解决此问题。我创建了这个示例来解决 z-index 堆叠问题...而且它也恰好解决了这个问题 (http://jsfiddle .net/ryanwheale/gz8v3/)。
This may help those who are choosing to drop support for IE7.
IE7 will always have a problem if the element is positioned (relative/absolute/fixed). In IE8+ the problem goes away if z-index is set to auto.
If you are needing to support IE7, or if you are needing to stack things using z-index, you must settle for a second wrapping DIV.
Edit 2012-05-29: I have created an example to show how to fix this problem. I created the example to solve a z-index stacking issue... and it just so happened to fix this problem too (http://jsfiddle.net/ryanwheale/gz8v3/).