2015-12-17 40 views
1

基本上我想要做的是将固定宽度的一个div粘贴到右侧,将固定高度的一个div粘贴到底部并使用一个div填充空格离开了。第三个div应该自动包装文本,其他div应该调整它们各自的高度和宽度到容器。调整div大小以匹配其他div的空格

这是我到目前为止有: https://jsfiddle.net/u0owp3jy/1/

body { 
 
     background-color: black; 
 
     box-sizing: border-box; 
 
    } 
 

 
    #wrapper { 
 
     display: table; 
 
     width: 50%; 
 
     height: 300px; 
 
     margin-top: 10px; 
 
\t margin-left: auto; 
 
\t margin-right: auto; 
 
     border: solid; 
 
     border-width: 3px; 
 
     border-color: red; 
 
    } 
 

 
    #flex { 
 
     background-color: blue; 
 
     /*width: calc(100% - 170px);*/ 
 
     width: auto; 
 
     float: left; 
 
     display: table-row; 
 
     height: 100%; 
 
     padding: 10px; 
 
     overflow-y: auto; 
 
    } 
 

 
    #static-left { 
 
     background-color: yellow; 
 
     float: right; 
 
     display: table-row; 
 
     height: 100%; 
 

 
     width: 140px; 
 
     border-left: solid; 
 
     border-width: 3px; 
 
     border-color: red; 
 
     overflow-y: auto; 
 
    } 
 

 
    #static-bottom { 
 
     display: table-row; 
 
     background-color: green; 
 
     height: 50px; 
 
     width: 100%; 
 
     border-top: solid; 
 
     border-width: 3px; 
 
     border-color: red; 
 
    }
<div id="wrapper"> 
 
     <div id="flex"></div> 
 

 
     <div id="static-left"></div> 
 

 
     <div id="static-bottom"></div> 
 
    </div> 
 

 

这样做的事情是,以获得正确的宽度为灵活的div,我需要使用计算( )这是坏的,另一件事是,底部div的边界不显示。

另外,如果您显然有width: auto;,则textwrapping不起作用。 如果可能,我想只用CSS做到这一点。它也应该在移动浏览器上工作。

+0

问题寻求帮助的代码必须包括必要的重现它最短的代码**在问题本身**。尽管您已经提供了一个示例链接,但如果链接无效,那么您的问题对于其他未来具有相同问题的SO用户将没有任何价值。 –

+0

这就是说...是固定的结构?...如果我们可以稍微调整结构,这非常简单。 –

+0

基本上我需要的是一种可调整大小的聊天窗口,右边是静态宽度的用户列表,底部是静态高度的文本输入,另一个是主要文本显示。 我不知道需要调整多少。你能详细说明一下吗? – sollniss

回答

3

请尝试以下解决方案。我用flexbox解决了这个问题。另外我为你的CSS做了一些优化,以获得更清洁和更好的CSS代码。

body { 
 
    background-color: black; 
 
} 
 
.top-wrapper { 
 
    align-items:stretch; 
 
    align-self:flex-start; 
 
    display:flex; 
 
    flex-direction:row; 
 
    height:100%; 
 
    max-height:250px; 
 
    width:100%; 
 
} 
 
#wrapper { 
 
    align-items:stretch; 
 
    border:3px solid #f00; 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap:nowrap; 
 
    height:300px; 
 
    margin:10px auto 0; 
 
    overflow:hidden; 
 
    width:50%; 
 
} 
 
#flex { 
 
    background-color:blue; 
 
    flex-grow:1; 
 
    overflow:auto; 
 
    padding:10px; 
 
    word-wrap:break-word; 
 
} 
 
#static-left { 
 
    background-color:yellow; 
 
    border-left:3px solid #f00; 
 
    overflow-y:auto; 
 
    width:140px; 
 
} 
 
#static-bottom { 
 
    background-color:green; 
 
    border-top:3px solid #f00; 
 
    box-sizing:content-box; 
 
    height:50px; 
 
    width:100%; 
 
}
<div id="wrapper"> 
 
    <div class="top-wrapper"> 
 
    <div id="flex"> 
 
     asdddddddddddd dddd dfdfd dfdfdfd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
    </div> 
 
    <div id="static-left"> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
     asd<br/> 
 
    </div> 
 
    </div> 
 
    <div id="static-bottom"> 
 
    asd<br/> 
 
    asd<br/> 
 
    asd<br/> 
 
    asd<br/> 
 
    </div> 
 
</div>

在这里你可以找到小提琴:https://jsfiddle.net/sebastianbrosch/0ypmw3xz/

+0

非常感谢。我仍然需要围绕柔性盒包裹头... 顺便说一句,从编辑之前的版本似乎工作,但编辑的一个吃下边的div。 当它变得太长时,是否也可以包装Flex div的文本,还是我需要在JavaScript中执行此操作? – sollniss

+0

您将代码中的'max-height:250px;'更改为'height:100%;'现在当我复制它时,底部div不再显示。如果我将它改回来,它会起作用。 单词包装就像一个魅力,谢谢。 – sollniss

+0

是的,我看到了,我更新了解决方案。 –