CSS to achieve chat bubble effect

CSS to achieve chat bubble effect

1. Rendering

JD Effect

Simulation Effect

2. Principle

Prepare a box with height and width of 0

Set a border around this box

Replace the unnecessary borders with transparent , and set the corresponding colors where they need to be displayed

If you need to change its size, just set the border width border-width width

Set the font-size and line-height to 0 to avoid affecting the display.

Finally, use positioning to set it to the desired position

3. Code

HTML Structure

<div class="square">
    <p class="triangle"></p>
</div>

CSS Styles

.square {
  position: relative;
  width: 400px;
  height: 200px;
  background: green;
  margin: 150px auto;
}
.triangle {
	position: absolute;
  top: -40px;
  left: 50%;
  margin-left: -20px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 20px;
  border-color: transparent transparent red transparent;
  font-size: 0;
  line-height: 0;
}

This is the end of this article about CSS chat bubbles. For more relevant CSS chat bubbles content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  MySQL 5.7 Common Data Types

>>:  Linux checkup, understand your Linux status (network IO, disk, CPU, memory)

Recommend

vue uses Ele.me UI to imitate the filtering function of teambition

Table of contents Problem Description The general...

Table td picture horizontally and vertically centered code

Html code: Copy code The code is as follows: <t...

Linux kernel device driver advanced character device driver notes

/****************** * Advanced character device d...

Summary of Common Mistakes in Web Design

In the process of designing a web page, designers...

JavaScript implements simple date effects

The specific code of JavaScript date effects is f...

Several methods of deploying multiple front-end projects with nginx

I have summarized 3 methods to deploy multiple fr...

border-radius method to add rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

How to delete special character file names or directories in Linux

Delete a file by its inode number First use ls -i...

Detailed explanation of unique constraints and NULL in MySQL

Preface A requirement I had previously made, to s...

Explanation of factors affecting database performance in MySQL

A story about database performance During the int...

Detailed explanation of the order of JS object traversal

Some of you may have heard that the order of trav...