0

我有一个div(带边框)。这在Firefox和IE 10上看起来不错(不确定旧版IE)。但是,有时IE会激活兼容模式,然后窗体(输入框和提交按钮)不在div中。是否有一些CSS来防止这种情况?窗体在IE兼容模式下掉出div

我的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在的jsfiddle

.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; 
} 

活生生的例子: http://jsfiddle.net/d3EdW/1/

截图: screenshot

回答

1

由于您的形式是浮动的,尝试CL将overflow: auto;放在表单的父级上,例如.box

+0

这只是隐藏窗体(或div窗体外的部分)。但我希望它看起来相同或不兼容模式 – Nin

+1

溢出:自动并不总是隐藏内容;它允许浏览器选择是否添加滚动条或隐藏内容,如果内容比容器更宽。这是清理花车的非常酷的方式。也许我误解了“哗众取宠”的样子 - 你能发布截图吗? – KatieK

+0

+1 @ KatieK的解决方案是正确的:http://jsfiddle.net/jonathansampson/d3EdW/4/show – Sampson