Are chat bubbles compatible with Bootstrap and Flex?

Can someone help me create chat bubbles within the bootstrap framework? I want to have right and left bubbles distinguished by two classes, such as right and left.

Each bubble should have a maximum width of 70%, but adjust to be smaller if the text is not too large.

Below is the code I have been working on:

<div class="d-flex flex-column">
  <div class="justify-content-end">
    <p class="col-6 msg right">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque neque est, viverra ac rhoncus et, cursus eu leo. Quisque in tristique libero, sed rhoncus neque. Ut at enim id ligula consequat tempus in nec magna. Donec vitae libero eget mi malesuada
      rutrum. Integer ornare ante at ligula venenatis, quis blandit urna euismod. </p>
  </div>
  <div class="justify-content-end">
    <p class="col-6 msg left">Integer ornare ante at ligula venenatis, quis blandit urna euismod.</p>
  </div>
  <div class="justify-content-start">
    <p class="col-6 msg right">Integer ornare ante at ligula venenatis, quis blandit urna euismod.</p>
  </div>
  <div class="justify-content-end">
    <p class="col-6 msg left">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque neque est, viverra ac rhoncus et, cursus eu leo. Quisque in tristique libero, sed rhoncus neque. Ut at enim id ligula consequat tempus in nec magna. Donec vitae libero eget
      mi malesuada rutrum. Integer ornare ante at ligula venenatis, quis blandit urna euismod. ge</p>
  </div>
  <div class="justify-content-start">
    <p class="col-6 msg right">Integer ornare ante at ligula venenatis, quis blandit urna euismod.</p>
  </div>
</div>

Here is the CSS code:

.msg {
  border-radius: 10px;
}

.msg.right {
  background-color:#CCC;
}

.msg.left {
  background-color:#555;
  color: white;
}

I have also created a jsfiddle with my code. I attempted to use justify-content-xxx, but it did not work as expected. Can anyone suggest a simpler way to achieve this? Thank you in advance.

https://jsfiddle.net/3a9vhydk/4/

Answer №1

To achieve the desired layout, you can add a float: right to the 'right' class and remove the justify-content property from the parent divs.

Check out the updated version of your code in this fiddle: https://jsfiddle.net/Mikkal24/0r5snvxu/

.msg.right {
  background-color:#CCC;
  float: right;
}

View the updated version here: https://jsfiddle.net/Mikkal24/534kn62w/

Important: Avoid using floats and use flexbox instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic Font Formatting in Rails Table Based on Conditions

I need to customize the font color of dynamic values based on the state_id. If incident.state_id = 1, the font should be red; if incident.state_id = 2, it should be yellow; and if incident.state_id = 3, it should be green. incident.state_id = 1 : state.na ...

Troubleshooting Vue.js rendering problems on Safari_BROWSER

I'm encountering a strange issue with my portfolio website, which is built using Vue and Laravel. The problem arises specifically in Safari - the project thumbnails don't display until the browser window is resized. Here's the relevant code ...

What is the best way to ensure that all elements inside a Grid item extend to the bottom, except for the text?

I currently have four columns within a Grid container, each structured as follows: <Grid item> <Typography>Big Title 1</Typography> <Card className={classes.stretchMe}> <CardContent> ...

Should you choose a pre-built CSS framework or create your own from scratch?

Have you come across a framework that meets your project needs with just a few tweaks, or have you forged your own path along the way? What advice do you have for someone facing this decision and focusing on priorities like: Implementing a CSS reset Refi ...

Animating Font Awesome content through CSS transitions

I am looking to animate a font awesome pseudo element on my website. Below is the HTML code I am working with: <li class="has-submenu"> <a onclick="$(this).toggleClass('open').closest('.has-submenu').find('.submenu&a ...

Transitioning the height of a Vue component when switching routes

I've been struggling to implement a transition slide effect on my hero section. The height of the hero is set to 100vh on the homepage and half of that on other pages. Despite trying various methods, I haven't been able to get it working properly ...

Is there a non-table layout method to achieve equal width sharing with a fixed solution?

If I have n different elements to be placed in the same horizontal space, each taking up 100% of the screen width, for example: <table style="width:100%;text-align:center;table-layout:fixed"> <tr> <td><input/></td ...

Encountering an issue with ng serve following the update of Angular, Material, and Bootstrap

Here is the package.json configuration: angular: 5.2.8 angular material : 5.1.1 angular/cli: "~1.7.3" bootstrap: "~4.0.0" Encountering an error while running ng serve: ERROR in ./node_modules/raw-loader!./node_modules/postcss-loader?? embedded!./nod ...

I am looking to incorporate a rounds div into the backdrop

My attempt to use border-radius did not solve my issue. I am trying to create a circular background for a specific section of the page, as shown in the image. For my first inquiry: I only want the circular background at the top of the page, not the botto ...

Collaborative Vue component: Clients need to manually import the CSS

I recently created a Vue component using TypeScript that resulted in a separate CSS file being generated after the build process. However, I noticed that when the client imports this component, the CSS file is not imported automatically and needs to be exp ...

Users who are utilizing Internet Explorer are unable to complete the search input field on my website

Hello, I am in the process of creating a website that frequently uses lengthy search terms. To optimize user experience, I have implemented a dropdown search bar inspired by the bootsnipp example below. While I have applied some custom styling to the desig ...

I'm experiencing some unusual behavior with the Windows media app when using HTML and CSS

I have a Windows Media Player box on my page, but it overlaps every piece of HTML code. How can I get it to move to the back so that I can still use it? Another problem is that everyone who visits my page needs a plugin to load it, even though most people ...

Padding the body of a single-page Angular application to ensure proper spacing and

How do I add padding to the body of a template in an angular ng-app? Where is the best place to include CSS for a ng-app rendered template? please refer to this fiddle for an example https://jsfiddle.net/aghsqnpa/ div.ngview { padding: 25px 50px 75p ...

A guide on incorporating Bootstrap into an npm project

After successfully setting up bootstrap and its dependencies, I'm struggling to figure out the correct way to include it in my index.html file. I attempted using require("bootstrap"), however, nothing appears to be loading. Any guidance on ...

Align the middle element in a dynamic row

There is a row consisting of three elements: left, center, and right. However, the problem lies in the fact that the center element is not aligned at the screen level, but rather at the row level. Is there a solution to align this element at the screen l ...

Browser inconsistencies result in varying appearance of Bootstrap selection in Firefox and Chrome

Issue with Bootstrap select rendering in Firefox and Chrome: Firefox: https://i.sstatic.net/HWEcR.png Chrome: https://i.sstatic.net/GBuDP.png Looking for ways to make the two browsers render consistently, preferably in Chrome's style. This questio ...

Reposition the checked box to the top of the list

My goal is to click on each item, and the selected item should move to the top of the list and be rendered at the top. However, I encountered an issue where when clicking on an item, it moves to the top but the item that replaces it also gets checked. Bel ...

What are the best ways to incorporate mistakes into my JavaScript mortgage calculator?

I am struggling to set up my calculator so that it triggers an error message if the APR goes over 25% or falls below 0. Also, the Loan Term should be greater than 0 and less than or equal to 40, otherwise display an error message. I have attempted differen ...

Utilizing Angular 2 with Bootstrap's popup modal feature

Is it possible to implement a popup modal in my Angular 2 application without relying on popular packages like ng2-opd-pop or similar solutions? I have included Bootstrap by importing it in my styles.css using '@import '../../../Content/bootstra ...

Shaky parallax movement

I recently created a website with a parallax effect, but I'm experiencing some performance issues with jittery movement. The page uses CSS3 transform scale to zoom in and out, and automatically resizes on page resize with JavaScript/jQuery. For the ...