I have a chat widget that I am adding some styling to. However I am having difficulty making the "user" chat bubbles align to the right of the screen.
When I use float right, with float left(for the other side) the divs no longer position correctly, in that they seem to just go to the right of the relative divs.
I would like it to also be able to append div's that will cause the overflow-y to create a scroll bar. Which without the float is already working as expected.
Below is the current version in a jsbin.
http://jsbin.com/utulay/1/edit
TLDR; trying to get the .chat-bubble-user divs to align to right of screen without float.
If you need to align it to the right, then set margin-left: auto and margin-right: 0; . Basically, to align a block element to one side horizontally, set the margin of that side to 0 and the opposite side to auto.
Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .
The short answer: clear: both. Floats work really well in small cases like when there's an element, such as a button, that you'd like to move to the right of a paragraph. But the real issue arises when you start using floats to lay out entire web pages. And the reason for that is: floats are not meant for layouts!
if you don't want use floats, just try with inline-block
, like so:
#chatWindow { text-align: right; } .chat-bubble-user { display: inline-block; text-align: left; }
JsBin (tested on Fx20): http://jsbin.com/awimev/2/edit
You can use float:right
on the user messages and put a clearfix div
after each one:
http://jsbin.com/utulay/2/edit
<div class="chat-bubble-user"> <div class="chat-bubble-glare-user"></div> <p>I have a question about kittens?</p> <div class="chat-bubble-arrow-border-user"></div> <div class="chat-bubble-arrow-user"></div> </div> <div class="clearfix"></div>
CSS
.clearfix:after { clear: both; content: "."; display: block; height: 0; visibility: hidden; } .clearfix { display: inline-block; } .clearfix { display: block; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With