【问题标题】:inline div issue in ie7ie7中的内联div问题
【发布时间】:2013-07-31 08:17:26
【问题描述】:

我在 JQuery 中创建了一个简单的小部件,它将 texbox 包装在一个 div 中,添加了一个明文按钮和一个占位符。在http://jsfiddle.net/BpkDN/ 处添加了这方面的主要内容,我在 CSS 中找不到的东西正在弄乱 ie7 中的样式。似乎适用于所有其他版本。

这是我的小部件生成的摘录:

CSS:

 ::-ms-clear {
      display: none;
  }
.jui-textbox {
    border: 1px solid #DADADA;
    position: relative;
    padding:0 !important;
    white-space: nowrap;
    background: #fff;
    overflow: hidden;
    height: 33px;
    line-height: 33px;
    display: inline-block;
    *display:inline;
    margin: 10px 0;

}

.jui-textbox input {
    background-color: transparent;
    color: #313131;
    height: 33px !important;
    line-height:33px\9;
    width: 300px;
    font-size: 14px;
    font-family: 'Open Sans', sans-serif;  
    padding: 0;
    margin: 0 5px !important;
    border: none;
    float:left;
}

.jui-textbox-placeholder {
    position: absolute;
    font-size: 14px;
    font-family: 'Open Sans', sans-serif;  
    color: #A1A1A1;
    height: 33px;
    line-height: 33px;
    padding: 0;
    margin: 0;
    left: 5px;
    overflow: hidden;
    cursor: text;
}


.jui-textbox-hover {
    border: 1px solid #CACACA;
}
.jui-textbox-active {
    border: 1px solid #a1a1a1;
}

.jui-textbox-clear.show{
    display:inline-block !important;
    *display:inline !important; 
}
.jui-textbox-clear {
    display:none;
    cursor: pointer;
    background: #fff;
    border-left: 1px solid #a1a1a1;
    width: 33px;
    height: 33px;
    background-image:url(icons/x.png);
    background-position:center;
    background-repeat:no-repeat;    
}
.jui-hoverable:hover,.jui-hoverable-hovered
{   background-color: #f1f1f1;}

textarea:focus, input:focus{
    outline: none;
}

HTML

<div class="jui-textbox">
    <div class="jui-textbox-placeholder" unselectable="on" style="font-size: 14px;">                                                
           Default
    </div>
    <input type="text" style="width: 300px;">
    <div class="jui-textbox-clear jui-hoverable jui-icons-x"></div>
</div>

【问题讨论】:

  • 样式发生了什么变化?

标签: html css internet-explorer-7


【解决方案1】:

试试这个:

CSS:

 ::-ms-clear {
      display: none;
  }
.jui-textbox {
    width: 300px;
    border: 1px solid #DADADA;
    position: relative;
    padding:0 !important;
    white-space: nowrap;
    background: #fff;
    overflow: hidden;
    height: 33px;
    line-height: 33px;
    display: inline-block;
    /**display:inline;*/
    margin: 10px 0;
}

.jui-textbox input {
    background-color: transparent;
    color: #313131;
    height: 33px !important;
    line-height:33px\9;
    width: 300px;
    font-size: 14px;
    font-family: 'Open Sans', sans-serif;  
    padding: 0;
    margin: 0 5px !important;
    border: none;
    float:left;
}

.jui-textbox-placeholder {
    position: absolute;
    font-size: 14px;
    font-family: 'Open Sans', sans-serif;  
    color: #A1A1A1;
    height: 33px;
    line-height: 33px;
    padding: 0;
    margin: 0;
    left: 5px;
    overflow: hidden;
    cursor: text;
}


.jui-textbox-hover {
    border: 1px solid #CACACA;
}
.jui-textbox-active {
    border: 1px solid #a1a1a1;
}

.jui-textbox-clear.show{
    display:inline-block !important;
    *display:inline !important; 
}
.jui-textbox-clear {
    display:none;
    cursor: pointer;
    background: #fff;
    border-left: 1px solid #a1a1a1;
    width: 33px;
    height: 33px;
    background-image:url(icons/x.png);
    background-position:center;
    background-repeat:no-repeat;
    position: absolute;
    right: 0;   
}
.jui-hoverable:hover,.jui-hoverable-hovered
{   background-color: #f1f1f1;}

textarea:focus, input:focus{
    outline: none;
}

HTML:

<div class="jui-textbox">
        <div class="jui-textbox-placeholder" unselectable="on" style="font-size: 14px;">
                Default
        </div>
        <input type="text" style="width: 300px;">
        <div class="jui-textbox-clear jui-hoverable jui-icons-x"></div>
    </div>
    <br/>
<div class="jui-textbox">
        <div class="jui-textbox-placeholder" unselectable="on" style="font-size: 14px;">
                 Focused
        </div>
        <input type="text"  style="width: 266px;">
        <div class="jui-textbox-clear jui-hoverable jui-icons-x show"></div>
</div>

在 IE7 (Vista) 中测试。

演示:http://jsfiddle.net/PENFT/

另一种解决方案,但不是很干净:

  • .jui-textbox 中删除width

  • float:left; 添加到".jui-textbox" 并将&lt;br/&gt; 更改为<br style="clear:both" />。

注意: &lt;br style="clear:both" /&gt; 太脏了。

【讨论】:

  • 啊,这似乎缩小了范围,因此将容器设置为内联会导致 ie7 中的问题。有没有办法在不明确设置 .jui-textbox 的宽度的情况下实现这一点?我宁愿它依赖于输入。如果不是,这可能是目前的解决方案!
  • 您可以添加“float:left;”在“.jui-textbox”中,并强制元素自行清除其子元素。
  • 考虑到这两种解决方案不符合您的第一个建议,只是在我的小部件代码中设置容器的宽度,因为无论如何我在那里创建它。为帮助干杯!
【解决方案2】:

在这种情况下,JavaScript 是简单的 hack,因为在 IE7 中 :focus 不起作用。看看ie7-js project

IE7.js 是一个 JavaScript 库 Microsoft Internet Explorer 行为 就像一个符合标准的浏览器。它 修复了许多 HTML 和 CSS 问题 使透明PNG正常工作 在 IE5 和 IE6 下。

升级 MSIE5.5-7 以兼容 MSIE8。

<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>
<![endif]-->

您也可以参考this SO questionIE7 doesn't support this pseudo class.

【讨论】:

  • 恐怕问题与聚焦无关,我只是简单地举了一个小部件状态的静态示例。问题是如何使用我当前的 CSS 在 ie7 中显示该 html。不过我会检查那个项目,看起来很有趣!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多