0

我想让一个固定大小的 div 向右浮动,剩下的空间需要留下。我以流畅的方式做到了这一点:

HTML:

<div class="container">
<div id="rightCntr">
</div>
<div id="leftCntr">
</div>
</div>

CSS:

#leftCntr { 
float: none; /* not needed, just for clarification */
background: #e8f6fe;
/* the next props are meant to keep this block independent from the other floated one */
width: auto;
overflow: hidden; 
}

#rightCntr { float: right; width: 213px;}

这在 Firefox 和 Chrome 中效果很好,但在 IE8 中却完全出错了。例子

4

3 回答 3

0

要在 IE 中获得正确的结果,您可以使用它来代替 float:right。

    position: absolute;
    right: 8px;
    text-align: right;
于 2013-01-16T09:00:05.640 回答
0

示例 jsBin: http: //jsbin.com/ixebuf/1/(在 IE8、Fx 上测试)(背景放置用于测试目的)

.container {
  width: 100%;
  overflow: hidden;
}
#rightCntr {
  float: right;
  width: 213px;
  background: gray;
}
#leftCntr {
   margin-right: 213px; 
   background: yellow;
}
于 2013-01-16T09:07:29.250 回答
-1
#leftCntr { 
    float: left; 

    /* not needed, just for clarification */ 
    background: #e8f6fe; 

    /* the next props are meant to keep this block independent 
     *  from the other floated one    
     */ 
    width: 100px; 
    overflow: hidden; 
    height: 100px; 
} 

#rightCntr { 
    float: right; 
    width: 213px; 
    border: 1px solid red; 
    background: red; 
    height: 100px; 
    width: 100px; 
    white-space: nowrap;
}

试试 this.remove 背景颜色

于 2013-01-16T09:53:37.257 回答