在IE兼容模式下,form脱离div

时间:2013-01-08 20:17:02

标签: css internet-explorer positioning ie8-compatibility-mode

我有一个div(带边框)。这在Firefox和IE 10上看起来不错(不确定IE的旧版本)。但是,有时IE会激活兼容模式,然后表单(输入框和提交按钮)会脱离div。是否有一些css调整来防止这种情况?

我的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>test</title>
  </head>

  <body>
    <div class="box">
       <h2 style="display:inline;">Some sample text</h2>

      <form id="frm">
        <input type="text" id="tb" />
        <input type="submit" class="button" />
      </form>
    </div>
  </body>
  </html>

和我的css

.box {
  display:block;
  height:40px;
  magin-left:5px;
  padding:5px 0 0 10px;
  width:740px;
  background:green;
  border:1px solid black;
}
h2 {
  margin:0 0 7px;
  padding:0;
  font:1.6em Arial;
  letter-spacing: -1px
}
#tb {
  width:225px
}
.button {
  float:right;
  width:93px;
  margin-left:5px;
  padding:2px 0
}
form {
  float:right;
}
#frm {
  margin-right:10px;
  margin-top:2px;
  width:330px;
}

jsfiddle的实例: http://jsfiddle.net/d3EdW/1/

截图: screenshot

1 个答案:

答案 0 :(得分:1)

由于您的表单已浮动,请尝试通过将overflow: auto;放在表单的父级上来清除它,例如.box

相关问题