I am struggling to show messages one by one using the 'li' tag, with the intention of having our messages appear on the right side and others on the left side in a react Chat app. However, the issue arises when I attempt to use float left or float right, causing all elements to collapse onto the same line like this
https://i.sstatic.net/nDN3S.png
The styling code for my react chat is as follows:
{this.state.chats.map(chat => (<div key={chat.timestamp}>
{this.state.user.uid === chat.uid ?(
<li className=" self" style={{listStyleType:"none",overflow:'hidden',marginLeft: 2 +'px',float:'right',display:'inline-block',
backgroundColor:"whitesmoke",margin:2 + "em",padding:13+'px',width:'max-content',borderBottomLeftRadius:11+'px',
borderBottomRightRadius:11+'px',borderTopLeftRadius:11+'px'}}>
<div className="message text-dark">{chat.content} </div>
</li>
):(
<li className="other" style={{listStyleType:"none",overflow:'hidden',marginLeft: 2 +'px',float:'left',display:'inline-block',
backgroundColor:"blanchedalmond",margin:2 + "em",padding:13+'px',width:'max-content',borderBottomLeftRadius:11+'px',
borderBottomRightRadius:11+'px',borderTopRightRadius:11+'px'}}>
<div className="message text-dark">{chat.content}</div>
</li>
)}
</div>
))}
Update: consider floating each individual div