如何阻止 Internet Explorer 的专有梯度过滤器切断应溢出的内容?

发布于 2024-08-31 06:17:12 字数 556 浏览 9 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(4

旧梦荧光笔 2024-09-07 06:17:13

这是可行的,尽管它是额外的标记。

<div id="box_that_wants_a_gradient">
    <div class="gradient_background_1"></div>
    <div class="gradient_background_2"></div>

My content

</div>

这种策略有一个好处,因为您可以添加多个渐变框并将它们的高度/宽度设置为父级的百分比,从而模拟 safari/moz 中允许的“颜色停止”行为。

例如:

<style>

#box_that_wants_a_gradient {
  position:relative;
  display:block;
  height:100px;
  width:100px}

.gradient_background_1 {
  position:absolute;
  height:20%;
  *cbf writing out microsoft filter code*;
  top:0;
  width:100%;
  left:0px}

.gradient_background_2 {
  position:absolute;
  height:80%;
  *still cbf writing out microsoft filter code*;
  top:20%;
  width:100%;
  left:0px}

</style>

This works, although it's extra markup.

<div id="box_that_wants_a_gradient">
    <div class="gradient_background_1"></div>
    <div class="gradient_background_2"></div>

My content

</div>

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:

<style>

#box_that_wants_a_gradient {
  position:relative;
  display:block;
  height:100px;
  width:100px}

.gradient_background_1 {
  position:absolute;
  height:20%;
  *cbf writing out microsoft filter code*;
  top:0;
  width:100%;
  left:0px}

.gradient_background_2 {
  position:absolute;
  height:80%;
  *still cbf writing out microsoft filter code*;
  top:20%;
  width:100%;
  left:0px}

</style>
昔日梦未散 2024-09-07 06:17:13

我知道这并不能特别回答您的问题,但请考虑一下您的听众。他们只是 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.

沙沙粒小 2024-09-07 06:17:13

我将父 div 的位置设置为相对位置并且它有效:)(或绝对位置,也工作得很好)

I set parent div's position to relative and it worked :) (or absolute, works fine too)

横笛休吹塞上声 2024-09-07 06:17:12

这可能会对那些选择放弃 IE7 支持的人有所帮助。

如果元素被定位(相对/绝对/固定),IE7 总是会出现问题。在 IE8+ 中,如果将 z-index 设置为 auto,问题就会消失。

如果您需要支持 IE7,或者需要使用 z-index 堆叠内容,则必须采用第二个包装 DIV。

<div class="position_me_and_stack_me_with_z-index">
  <div class="give_me_a_filter">
    Content goes here
  <div>
</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.

<div class="position_me_and_stack_me_with_z-index">
  <div class="give_me_a_filter">
    Content goes here
  <div>
</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/).

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