javascript - 定位 div #2

标签 javascript jquery html css

我是网络开发的新手,我正在尝试使用 SQL 创建一个简单的聊天页面。这是我目前拥有的:Codepen

HTML:

<body>
    <div id="overlay"></div>
    <div id="header">
        <div id="logo">
            <a href="http://csgovoid.net"></a>
        </div>
    </div>

    <div id="chat_extended">
        <div id="chat_area"></div>
        <input id="chat_input" type="text" placeholder="Chat...">
        <button id="send_button" onClick="send()">SEND</button>
    </div>
</body>

CSS:

html,
body {
    background-color: #333;
    margin: 0;
    padding: 0;
}

#overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.2;
    background: #ccc;
    background: -webkit-linear-gradient(right top, #8900AB, #282828);
    background: -o-linear-gradient(top right, #8900AB, #282828);
    background: -moz-linear-gradient(top right, #8900AB, #282828);
    background: linear-gradient(to top right, #8900AB, #282828);
}

#header {
    position: absolute;
    background: #404040;
    width: 100%;
    height: 10%;
    border-bottom: 10px solid #9800AB;
}

#logo {
    position: absolute;
    background-image: url(http://csgovoid.net/img/logo.png);
    background-repeat: no-repeat;
    background-size: contain;
    width: 100%;
    height: 100%;
}

#chat_extended {
    position: absolute;
    background: #404040;
    margin-top: 3.15%;
    width: 20%;
    height: 100%;
    float: right;
    border-left: 10px solid #9800AB;
    text-align: center;
    padding-top: 5%;
}

#chat_area {
    position: absolute;
    background: #ccc;
    width: 100%;
    height: 100%;
    text-align: left;
}

聊天窗口应左对齐,聊天区域位于聊天窗口内,如下所示: Preview

最佳答案

使用 position: absolute 时不需要 float:right,只需删除它并添加 right: 0 到#chat-extended

#chat_extended {
position: absolute;
background: #404040;
width: 20%;
height: 100%;
border-left: 10px solid #9800AB;
text-align: center;
right: 0;

希望这对您有所帮助!

关于javascript - 定位 div #2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36316294/

相关文章:

jquery - Ajax 将列表作为字符串发送,而不仅仅是列表

PHP post 提交后抛出 404 错误

javascript - HTML 中的无效字符阻止我的菜单切换?

javascript - jQuery .delegate 不工作

javascript - 创建多次使用的函数

javascript - 刷新页面后图片位置不正确

javascript - AngularJS 输入类型数字在输入字母时不会更新模型

javascript - 我们如何使用 JavaScript 或 jQuery 将 HTML 表单数据保存为 xml 格式?

javascript - 为什么我的 DataTables 插件根本不起作用?

html - 如何使 HTML 按钮不重新加载页面