Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right Side align without float

Tags:

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.

like image 581
zmanc Avatar asked Apr 29 '13 11:04

zmanc


People also ask

How do you align a button to the right without floating it?

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.

How do you align your right side?

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 .

Is it good to use float?

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!


2 Answers

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

like image 167
Fabrizio Calderan Avatar answered Nov 15 '22 12:11

Fabrizio Calderan


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; } 
like image 29
martincarlin87 Avatar answered Nov 15 '22 12:11

martincarlin87