html - 使用 css 排序 div 元素

标签 html css

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Chat</title>
        <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
            <div id="header">   
                <h1 id="titleRoom"></h1>
                <h3>Online Users:</h3>
                <div id="online_users"></div></br>
                <button id="buttonRoom" type="button" name="button">Create Chatroom</button><button id="buttonLobby" type="button" name="button">Back Lobby</button></div>
                <div class="chatArea">
                    <ul class="messages"></ul>
                </div>
                <div class='inputContainer'>
                    <input class="inputMessage" placeholder="Type here..."/><button id="sendButton" type="button" name="button">Send</button>
                </div>
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script src="/socket.io/socket.io.js"></script>
        <script src="/js/client.js"></script>
    </body>
</html>

我需要始终在顶部 div id="header",始终在按钮 div class='inputContainer' 和中间(占据页面的其余部分)div class="chatArea"而没有那个 div class="chatArea"覆盖或被 div id="header"或 div class='inputContainer' 覆盖。有谁知道这样做的 css 代码?

最佳答案

Using flexbox, this is easy to achieve.

Set the wrapper containing your 3 compartments to display: flex; and give it a height of 100% or 100vh. The height of the wrapper will fill the entire height, and the display: flex; will cause all children of this wrapper which has the appropriate flex-properties (for example flex:1;) to be controlled with the flexbox-magic.

示例标记:

<div class="wrapper">
    <header>I'm a 30px tall header</header>
    <main>I'm the main-content filling the void!</main>
    <footer>I'm a 30px tall footer</footer>
</div>

相关的 CSS 是:

.wrapper {
   height: 100vh;
   display: flex;

   /* Direction of the items, can be row or column */
   flex-direction: column;
}

header,
footer {
    height: 30px;
}

main {
    flex: 1;
}

关于html - 使用 css 排序 div 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43617286/

相关文章:

css - 无法将 div 层定位在 html slider 之上

javascript - 单击两个输入的相同标签名称的关闭图标时取消选中选中的输入

html - 分辨率改变时背景移动

css - 位置 :fixed on element in ie7/8 and problems with the scrolling of the content inside it

javascript - 使用 Google Chrome 扩展程序编辑页面源代码

javascript - 使用 javascript 进行打印时限制每页的行数

html - "100%"的 DIV 宽度滚出页面右端

javascript - 使用带有 inject = true 的 HtmlWebpackPlugin 不会缩小 ES6 代码

html - 使用具有背景颜色的特定 div,而不影响主体的背景

html - 包装时有没有办法改变元素的顺序?