What is the best way to implement CSS chat messages with rounded borders?

I am currently compiling a list of messages sent and received on our chat platform. Here is the current layout:

Check out the preview

However, I would like to revamp this structure to something like the following:

Take a look at the new preview here

I need guidance on how to update the design. Below are the CSS and HTML snippets I am working with:

ul {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

ul li {
  padding: 5px 10px;
  display: block;
  color: white;
  background: #444;
  height: 30px;
  list-style-type: none;
}

ul li.out {
  background: cornflowerblue;
}
<ul>
  <li class="out">1</li>
  <li>2</li>
  <li>3</li>
  <li class="out">4</li>
  <li class="out">5</li>
  <li>6</li>
  <li class="out">7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li class="out">11</li>
</ul>

Answer №1

Below is an example of how you can achieve this, make sure to read the comments within the code:

ul {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

ul li.out {
  background: cornflowerblue;
}
ul li {
  padding: 5px 10px;
  position:relative;
  z-index:0;
  color: white;
  background: #444;
  height: 30px;
  list-style-type: none;
  border-radius:10px; /* apply border radius to all */
}

/* remove top radius if the next one is the same*/
.out + .out,
:not(.out) + :not(.out) {
  border-radius:0 0 10px 10px;
}
/* create a pseudo element to overlap the bottom radius of the previous one */
.out + .out:after,
:not(.out) + :not(.out):after {  
  content:"";
  position:absolute;
  z-index:-1;
  background:inherit;
  left:0;
  right:0;
  height:10px;
  bottom:calc(100% + 10px);
}
<ul>
  <li class="out">1</li>
  <li>2</li>
  <li>3</li>
  <li class="out">4</li>
  <li class="out">5</li>
  <li>6</li>
  <li class="out">7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li class="out">11</li>
</ul>

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

Is there a way to stop the top nav from covering the first element of the side-nav in specific situations?

I'm grappling with the issue of how to prevent the side-nav from obscuring the top element in the vanilla Bootstrap 4 example provided below. Any tips? (Problem resolved - check below for solution) This problem is occurring not only on my website bu ...

Updating content with Ajax in Laravel

Hey, I'm currently facing an issue with my update functionality. Below is the blade code snippet: <div class="form-group floating-label" id="role_colaboration1"> <select name="{{$role}}[]" id="role" class="form-control"> ...

Transitioning to mobile-friendly web design

Just completed my very first page for a personal portfolio website. As a novice in web development, I made the width of my site 1600px to match the background image. Now, my goal is to make the page responsive. However, when I adjusted the width to 100%, ...

Is it possible to include a class in a .json object for use with CSS?

I am working with a .json object that is displayed using Angular's ng-bind directive: <p ng-bind-html="paragraph" ng-repeat="paragraph in content.sections[0].pages[1].paragraphs"></p> Here is the structure of the .json data: { "header ...

I am working with a JSON Object in JavaScript and need to retrieve a key using a String variable

Working with a JSON Object in JavaScript can be tricky, especially when trying to access keys stored as Strings using the dot operator. Consider this example of JSON code: "values" : [ { "prop0" : "h", "prop1" : "pizza", "prop2" : "2014- ...

What is the most efficient way to gather all form inputs and then transmit them to an email address?

Could you please help me with creating a form page that collects user input data and sends it to my email? I am looking for solutions using only HTML, CSS, PHP, or JavaScript. Here is a preview of the page: Below is the PHP code snippet I've been wo ...

Using flexbox auto margin within nested elements: A guide

Is it possible to achieve consistent margins between the heading and list items using flexbox? section { display: flex; background: #eee; } h1 { background: #bbb; } ul { display: flex; flex: 1; list-style-type: none; background: #ccc; ...

Extract the <br /> tag exclusively from the content inside the div

My experience with WooCommerce has led me to the need to include <br> within a product name. However, this break appears differently as <br /> in the .woocommerce-breadcrumb element. This is what the breadcrumb currently display ...

Div element obstructing the ability to view markers

Issue with a positioned DIV over Google Maps: The DIV is causing accessibility problems for the map, taking up the entire width when it should stop at the green square borders. Interaction with the map is limited to the very bottom after the green square. ...

Ways to conceal a DIV element by clicking outside of it

I am facing an issue with hiding a div when clicking outside of it. Here is the code I have tried: <div id="mydiv">The div must be above button</div> $('#mydiv').click(function(e) { e.stopPropagation(); }); $(do ...

Interactive vertical table headers and clickable cells

I am struggling with making cells clickable in a table I created with vertical text headings. The table is meant to document file formats used within our system, where currently only the text link is clickable to lead to the documentation. However, I aim t ...

Adding text to a hyperlink when hovering over it

I have searched extensively to find a solution for this issue, but I simply want to include a greater-than sign in my link when it is hovered over. I prefer not to use images or tables and so on. As someone more focused on backend development, I grasp the ...

Adjust div to match the width of the image

My portfolio page features an image display with zoom functionality. Here is the code I am currently using: http://codepen.io/Mpleandro/pen/LvrqJ The division that showcases the image has a class called .display, located on line 13 of the HTML file and CS ...

Creating a fully responsive HTML page with a fullscreen image background

Seeking help from someone who can assist me. I have a challenge in creating a webpage with a background image that fills its <div>. Here is the code I used: <style type="text/css> .myclassdiv { background-image:url('IMAGEURL') ...

Is it possible to use the HTML script tag without specifying the type attribute as JavaScript? <script type="text/html"></script>?

While examining the source code of an HTML page, I stumbled upon the following snippet: <script id="searchItemTemplate" type="text/html"> <# var rows = Math.floor((Model.RecordsPerPage - 1) / 3 + 1); for (var i = 0; i < rows; ++i){ ...

Bootstrap collapsible panel with unique off-center design

I am currently working on customizing a bootstrap collapsible panel that has an off-center indicator arrow. My goal is to center the indicator arrow with CSS. Here's the CSS code I have implemented: .panel-heading a:after { ...

Angular encountering a null value within a pre-existing nested object

Upon receiving a fully populated object from my server to my angular service, everything appears correct in Postman and when I use JSON.stringify in the Angular component. However, I encounter an issue when trying to access nested objects within the view. ...

Obtain information from a dataTable by utilizing ajax

I've been attempting to showcase dataTable data using ajax, but unfortunately, it's not working as expected. Below is my jquery code snippet: $('#example').DataTable({ ajax: { type: 'GET', ...

Moving away from using Textarea, an alternative option is editable divisions. However, the issue arises when input

When using the following code: <div contentEditable="true" name="content"></div> instead of a Textarea in a form, I am unable to submit the input taken from the editable division above. The reason for using an editable division is to dynamic ...

Steps to center the search form in the navbar and make it expand in Bootstrap 5

I'm utilizing Bootstrap v5.1.3 and have included a navbar as shown below: navbar Here is the code for that implementation: <div class="container"> <nav class="navbar navbar-expand-lg navbar-light bg-light& ...