无论屏幕大小如何,我都试图并排 float 两个div。目前在IE 7中,如果我调整窗口大小,则一个div会降到另一个。我认为是因为div2包含一个表,并且一旦窗口的边缘碰到该表,它就会降到div1以下。

我目前拥有的功能可以在IE9和Firefox中使用,但需要在IE6 + 7中使用。我尝试了此解决方案CSS floats - how do I keep them on one line?,但似乎没有帮助。同样,我认为这可能是由于这些div中的内容所致。
如何复制它?

码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>

<style>
  #wrapper {
    min-width:510px;
    width: auto !important;
    width: 510px;
    border: 1px solid red; }

  #div1 {
    float:left;
    color:blue;
    width:500px;
    border: 1px dashed purple;
    height: 400px;}

  #div2 {
    margin-left:505px;
    border:1px dashed purple;}

  #div2 table{border: 1px dotted green;}

</style>
</head>
<body>
  <div id="wrapper">
    <div id="div1" >
      Sometimes I contain a table and sometimes I contain an object. Bother of which displays a chart
    </div>
    <div id="div2">
       <table>
        <tr>
         <td> I am normally a report
           asdfasdfads
           dsafasdfasdfasdfasdfadsfasdfasdadfadsfadfsdfasdfsdffGreat Thanks, today has been quiet hot but somehow a bit cooler than this time last year.
         </td>
       <td></td>
       </tr>
      </table>
    </div>
  </div>
</body>
</html>

可以在此处找到一个实时示例http://jsbin.com/awijew/11

最佳答案

删除左边距:505px;在div2上

关于css - 并排 float 两个div,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6937887/

10-11 23:41