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

7 Ways to Write a Vue v-for Loop

Table of contents 1. Always use key in v-for loop...

Linux sar command usage and code example analysis

1. CPU utilization sar -p (view all day) sar -u 1...

Linux system to view CPU, machine model, memory and other information

During system maintenance, you may need to check ...

Why does your height:100% not work?

Why doesn't your height:100% work? This knowl...

Several specific methods of Mysql space cleaning

Table of contents Preface 1. Check the file disk ...

Detailed explanation of long transaction examples in MySQL

Preface: The "Getting Started with MySQL&quo...

Pure JavaScript to implement the number guessing game

Develop a number guessing game that randomly sele...

Research on the effect of page sidebar realized by JS

Table of contents Discover: Application of displa...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

How to build Jenkins+Maven+Git continuous integration environment on CentOS7

This article takes the deployment of Spring boot ...

CSS example code for setting scroll bar style

The CSS implementation code for setting the scrol...

Linux centOS installation JDK and Tomcat tutorial

First download JDK. Here we use jdk-8u181-linux-x...

Tutorial on installing MySQL 5.6 on CentOS 6.5

1. Download the RPM package corresponding to Linu...