javascript - How to invert the anchoring inside a `<div>` to the bottom instead of the top? -
i'm building chat application , need messages anchor bottom of message index , grow rather hanging top of message index. i'm building in react, following code jsx.
message index:
<div classname="chat-message-index"> {this.state.activechannel.messages.map(function(message{ return <message key={message.sid} message={message} />; })} </div> messages (rendered within index):
<div classname="chat-message"> <b classname="name">{this.state.author}</b><br/> <span dangerouslysetinnerhtml={{__html: this.state.message.body}} /> </div> css:
.chat-message-index { height: calc(~"100vh - 250px"); position: absolute; overflow-y: scroll; width: 100%; background-color: silver; display: list-item; } .chat-message { position:relative; padding:10px; margin:22px 45px 22px 20px; color:#fff; background:#43464b; background:-webkit-gradient(linear, 0 0, 0 100%, from(#aeb5ba), to(#43464b)); background:-moz-linear-gradient(#aeb5ba, #43464b); background:-o-linear-gradient(#aeb5ba, #43464b); background:linear-gradient(#aeb5ba, #43464b); -webkit-border-radius:10px; -moz-border-radius:10px; border-radius:10px; } i have tried every css trick can think of, every idea i've found through googling , here on so, , can't find anything. closest i've gotten using transform:rotate(180deg); on both message index , messages, inverts scrolling , causes scroll bar appear on left side of index, doesn't work. can make approach work, feels hacky , gut feeling cause headaches down road...
does know how invert anchoring <div>? want first message display @ bottom of message index <div> , each additional message stack on top of <div>'s came before.
flexbox can that:
.chatbox { margin: 1em auto; width: 150px; height: 500px; border: 1px solid grey; display: flex; flex-direction: column-reverse; justify-content: flex-start; text-align: center; } .message { background: lightgreen; margin-bottom: .25em; padding: .25em 0 0 0; border-bottom: 2px solid green; } <div class="chatbox"> <div class="message">message 1</div> <div class="message">message 2</div> <div class="message">message 3</div> <div class="message">message 4</div> <div class="message">message 5</div> <div class="message">message 6</div> <div class="message">message 7</div> <div class="message">message 8</div> <div class="message">message 9</div> <div class="message">message 10</div> <div class="message">message 11</div> <div class="message">message 12</div> </div>
Comments
Post a Comment