using clear: bothon yours li, you will get the desired effect.
.chat li {
margin-bottom: 15px;
padding: 10px 20px;
border-radius: 20px;
margin-bottom:10px;
clear: both;
}
<body>
<style>
.chat {
list-style: none;
padding: 0;
overflow: hidden;
margin: 0;
}
.chat li {
margin-bottom: 15px;
padding: 10px 20px;
border-radius: 20px;
margin-bottom:10px;
clear: both;
}
.chat li:nth-child(odd) {
float: right;
background-color: #52adf4;
color: #fff;
}
.chat li:nth-child(even) {
float: left;
background-color: #e9e7e8;
color: #333;
}
</style>
<ul class="chat">
<li>Hi Joe</li>
<li>Hi, how're u?</li>
<li>Fine, how it going bro?</li>
<li>Thanks as usual</li>
</ul>
</body>
Run codeHide result source
share