18

我有两个<div>leftcontents。这两个在具有min-width:960px;. left有固定宽度,但我想让内容灵活,最小宽度为700px,如果屏幕更宽,请将其粘贴到屏幕的右边界。
截屏

CSS:

#wrapper
{
    min-width:960px;
    margin-left:auto;
    margin-right:auto;
}
#left
{
    width:200px;
    float:left;
    background-color:antiquewhite;
    margin-left:10px;
}
#content
{
    min-width:700px;
    margin-left:10px;
    width:auto;
    float:left;
    background-color:AppWorkspace;
}

JSFiddle:http: //jsfiddle.net/Zvt2j/

4

5 回答 5

10

You can overflow:hidden to your #content. Write like this:

#content
{
    min-width:700px;
    margin-left:10px;
    overflow:hidden;
    background-color:AppWorkspace;
}

Check this http://jsfiddle.net/Zvt2j/1/

于 2013-01-14T13:34:23.653 回答
5

你可以使用 css3 灵活的盒子,它会是这样的:

首先,您的包装器包装了很多东西,因此您需要一个仅用于 2 个水平浮动框的包装器:

 <div id="hor-box"> 
    <div id="left">
        left
      </div>
    <div id="content">
       content
    </div>
</div>

你的css3应该是:

#hor-box{   
  display: -webkit-box;
  display: -moz-box;
  display: box;

 -moz-box-orient: horizontal;
 box-orient: horizontal; 
 -webkit-box-orient: horizontal;

}  
#left   {
      width:200px;
      background-color:antiquewhite;
      margin-left:10px;

     -webkit-box-flex: 0;
     -moz-box-flex: 0;
     box-flex: 0;  
}  
#content   {
      min-width:700px;
      margin-left:10px;
      background-color:AppWorkspace;

     -webkit-box-flex: 1;
     -moz-box-flex: 1;
      box-flex: 1; 
}
于 2013-01-14T13:38:07.743 回答
2
#wrapper
{
    min-width:960px;
    margin-left:auto;
    margin-right:auto;
    position-relative;
}
#left
{
    width:200px;
    position: absolute;
    background-color:antiquewhite;
    margin-left:10px;
    z-index: 2;
}
#content
{
    padding-left:210px;
    width:100%;
    background-color:AppWorkspace;
    position: relative;
    z-index: 1;
}

如果您需要 右侧的空格#left,则添加border-right: 10px solid #FFF;to#left并添加10pxpadding-leftin#content

于 2014-06-03T00:56:28.237 回答
1

CSS auto-fit container between float:left & float:right divs solved my problem, thanks for your comments.

#left
{
    width:200px;
    float:left;
    background-color:antiquewhite;
    margin-left:10px;
}
#content
{
    overflow:hidden;
    margin-left:10px;
    background-color:AppWorkspace;
}
于 2013-01-14T13:34:22.797 回答
1

我已经更新了你的jsfiddle,这是你需要做的 CSS 更改:

#content
{
    min-width:700px;
    margin-right: -210px;
    width:100%;
    float:left;
    background-color:AppWorkspace;
}
于 2013-01-14T13:36:42.980 回答