简体   繁体   English

CSS布局的相对宽度,固定混合

[英]Relative width for a CSS layout, fixed and fluid mix

I am trying to make a chatroom layout like the following: 我正在尝试进行如下聊天室布局:

聊天室布局

Now my problem is that I am not sure how to have the container box occupy the whole width and height (with valid doctype) and then make the center div grow if the window grows keeping the rest constant. 现在我的问题是,我不确定如何使容器框占据整个宽度和高度(具有有效的doctype),然后在窗口增大时保持居中的div不变,从而使居中的div增大。

i am well aware of js/css. 我很了解js / css。 so i just need some beginning guideline. 所以我只需要一些入门指南。 i would like to avoid javascript to process and then set heights and widths. 我想避免javascript处理然后设置高度和宽度。

body, html {
    height: 100%;
    margin: 0;
    padding: 0;
}
#container {
    height: 100%;
    height: auto !important;
    margin: 0 auto;
    min-height: 100%;
    position: relative;
    width: 100%;
}
.header {
    display: block;
    height: 100px;
    width: 100%;
}
.body-left {
    float: left;
    width: 70%;
}
.body-right {
    float: right;
    width: 30%;
}
.clear {
    clear: both;
}
.footer {
    float: left;
    width: 70%;
}

and HTML 和HTML

<div id="container">
    <div class="header"></div>
    <div class="body-left"></div>
    <div class="body-right"></div>
    <div class="clear"></div>
    <div class="footer"></div>
</div> 

That is it if that is what you seek 就是这样,如果您要寻找的是

or use the following JavaScript to find out the height and assign it to your container : 或使用以下JavaScript找出高度并将其分配给您的容器:

function getWindowHeight() {
    var windowHeight = 0;

    if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }

    return windowHeight;
}

window.onload = init;

function init() {
    document.getElementByID("container").style.height = getWindowHeight() + "px";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM