I am trying to make a simple chat application and can't seem to display the chat text belonging to one user stick to the left while the other user's message sticks to the right.
Here is a sample of the code:
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.user1 {
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
padding: 0 2px 2px 2px;
text-align: right;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
}
<div class="chat-session">
<div class="user1">Hello</div>
<div class="user2">Hi</div>
<div class="user1">What's up?</div>
<div class="user2">Not much</div>
</div>
I would like the divs to fit the text size and user2's div to align right. I have tried display: inline-block;
to fit the divs, but that just displays them all on the same line. I have also tried float: right;
and float: left;
but that also displays them on the same line.
Can someone help?