An essential part of this is the following CSS:
.rbubble{ background: lightgreen; margin-left: 100%; transform: translateX(-100%); word-wrap: avoid-break; }
We push it all out of the container to the right, and then drag it to the left using transform: translateX(-100%);
. No clutter float
and no extra wrappers required.
.outer{ display: block; } .lbubble , .rbubble { position: relative; padding: 5px; -webkit-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 2px 2px 10px 0px #616161; box-shadow: 2px 2px 7px 0px #616161; display: inline-block; margin-bottom: 8px; } .lbubble{ background: lightblue; } .rbubble{ background: lightgreen; margin-left: 100%; transform: translateX(-100%); word-wrap: avoid-break; } .lbubble:after { content: ""; position: absolute; top: 5px; left: -8px; border-style: solid; border-width: 10px 14px 10px 0; border-color: transparent lightblue; width: 0; z-index: 1; } .rbubble:after { content: ""; position: absolute; top: 5px; right: -8px; border-style: solid; border-width: 10px 0 10px 14px; border-color: transparent lightgreen; width: 0; z-index: 1; }
<div class='outer'> <div class="rbubble"> Right Bubble with align right</div> </div> <div class='outer'> <div class="lbubble"> Left Bubble it should be on 2nd line with align left </div> </div>
source share