【问题标题】:solve this style problem for IE6 and IE7为 IE6 和 IE7 解决这个样式问题
【发布时间】:2011-08-25 01:56:02
【问题描述】:

首先我会告诉你这个问题,它只发生在 IE6/IE7 上

如你所见,当innerHtml的长度不长时,没问题;但是当它“更长”时,设置为 bg 图像的精灵会重复,并且文本会跳转到下一行...

现在,CSS

.contButton {
    list-style: none;
    float: right;
}


.contButton p {
    float: left;
    display: inline; /*For ignore double margin in IE6*/
    margin: 0 0 0 10px !important;
}
.contButton a {
    text-decoration: none !important;
    float: left;
    color: #FFF;
    cursor: pointer;
    font-size: 14px !important;
    line-height: 21px;
    font-weight: bold !important;
}
.contButton span {
    margin: 0px 10px 0 -10px;
    padding: 3px 8px 5px 18px;
    position: relative; /*To fix IE6 problem (not displaying)*/
    float:left;
}
/*ESTADO NORMAL AZUL*/
.contButton p a {
    background: url(../nImg/spriteBotones.png) no-repeat right -214px;
    _background: url(../nImg/spriteBotones.gif) no-repeat right -214px;
    color: #FFF;    
}


.contButton p a span {
    background: url(../nImg/spriteBotones.png) no-repeat left -214px;
    _background: url(../nImg/spriteBotones.gif) no-repeat left -214px;
}

还有HTML:

<div class="">
....
<div class="contButton mt10">
   <p><a tabindex="" title="acceder" href="#"><span>ver disponibilidad</span></a></p>
</div> 
...
</div>

这是背景图。 ![精灵][2]

尝试过:

<!--[if IE lte 7]>



<style type="text/css"> 
/*
.contNombrePrecioHtl .contButton p a{ height:20px;  }
.contNombrePrecioHtl .contButton p a span{ height:20px; width:auto; }  */
</style>
<![endif]-->

但这并没有解决问题...

PS: class="mt10" 这只是margin-top:10px;

知道如何为光荣的 IE6/7 解决这个问题吗?

【问题讨论】:

  • IE7 应该支持最大宽度,所以你可以设置正确的(你必须找出它是什么)最大宽度,它永远不会是两行。不知道如何处理 IE6
  • 那么应该会发生什么?无论多长,文本都应始终保持在一行?
  • 精灵应该重复一点,文本在同一行;如果你意识到, 有左边的背景,而 有右边的背景......

标签: css internet-explorer-7 internet-explorer-6


【解决方案1】:

尝试将white-space: nowrap 添加到.contButton

【讨论】:

  • 这样我在 IE 中看到它完美,但在 FF 中右圆角消失了;我必须将其作为 hack 应用吗??
  • 您可以使用*white-space: nowrap 仅在IE7及更低版本中应用。
  • f 我将它设置为 .contButton 它适用于两者;你怎么看?? (如果我能更好地解决这个问题)
  • 如果它在.contButton 上的所有浏览器中都可以使用,那么当然,只需将其设置为即可。记住,我看不到你在看什么——我只是在“猜测”。
【解决方案2】:

改变这个:

.contButton span {
  margin: 0px 10px 0 -10px;
  padding: 3px 8px 5px 18px;
  position: relative; /*To fix IE6 problem (not displaying)*/
  float:left;
  white-space: nowrap;
}

【讨论】:

  • 这样我在 IE 中看到它很完美,但在 FF 中右圆角消失了;我必须将其作为 hack 应用吗??
  • 如果我将它设置为 .contButton 它适用于两者;你觉得呢??
【解决方案3】:

我认为这两个 IE 版本都没有问题,可能只是较新的浏览器对这个特定的东西不太严格。我没有测试任何东西,但“display:inline-block”有时对我有帮助。仍然它似乎不是最有效的解决方案。此处的宽度似乎受到限制,如果您不希望文本“跳转”到第二行,则不应给该东西固定宽度...

【讨论】:

  • 忘记我对固定宽度的评论,你的代码中没有固定的..:P
【解决方案4】:
  1. 您可以尝试将overflow:hidden 添加到带有float:left 的元素的每个父元素吗?在这种情况下,您必须将其添加到每个 div、p 和 a。我不确定您的实际代码是否最优。
  2. 此外,浮动:左;和 display: inline 一起没有意义。这可能是奇怪行为的原因。删除 display: inline (请记住将 overflow: hidden 添加到其父级),它应该可以工作。 但尚未测试。

更新:

显然正如问题的作者提到的那样 float:left + display: inline 修复了 IE6 浮动元素的双边距错误。

【讨论】:

【解决方案5】:

pspan 之类的元素定义尺寸总是介于棘手不可能 之间,因为它们是内联元素。我建议修改周围的块元素 div.contButton。

除了高度之外,您还应该将溢出设置为隐藏:

.contButton { 
    height:20px; 
    width:219px; 
    overflow: hidden;
}

【讨论】:

  • 问题是我不能设置这么多的宽度,因为有时文本“更短”,例如:(
  • 顺便说一句,您可以像这样破解您想在 IE 中应用的样式:* html div.contButton { /* IE-only-Formatting */ }
  • -1: p 不是内联元素!如果需要,请查看proof on fiddle
  • 我只是从您的(上一个)示例中取了 219 像素...您可以将宽度保留为“自动”。在父 DIV 上使用 overflow:hidden 时,PA 可能会高于 DIV,但不会扩展 DIV。内容将在 20px 高度处被截断。
猜你喜欢
  • 1970-01-01
  • 2011-09-19
  • 2011-03-07
  • 2010-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多