简体   繁体   中英

Positioning divs #2

I'm fairly new to web development and I'm trying to create a simple chat page using SQL. This is what I currently have: 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;
}

The chat window should be aligned to the left, with the chat area within the chat window, like this: 预习

You don't need float:right when using position: absolute, just remove that and add right: 0 to #chat-extended

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

Hope this helps!

The float property does not work on absolutely positioned elements.

On #chat_extended , Replace this:

float: right;

with this:

right: 0;

Absolute positioning like that isn't really a best practice for a layout like this, so once you get more comfortable, you might want to change it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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