zmanc
zmanc

Reputation: 5399

Right Side align without float

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.

Upvotes: 22

Views: 58670

Answers (3)

Kondas Lamar Jnr
Kondas Lamar Jnr

Reputation: 143

it has been a problem for sometime until. You only have to use

text-align:right;
display-inline:block;

all in the parent member;

Upvotes: 0

martincarlin87
martincarlin87

Reputation: 11042

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;
}

Upvotes: 8

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123367

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

Upvotes: 28

Related Questions