Example code for implementing the "plus sign" effect with CSS

Example code for implementing the "plus sign" effect with CSS

To achieve the plus sign effect shown below:

Plus Sign

To achieve this effect, you only need a div element.

CSS is needed for before, after, and border properties.

First set a div note

 <div class="add"></div>

Set another border:

.add {
  border: 1px solid;
  width: 100px;
  height: 100px;
  color: #ccc;
  transition: color .25s;
  position: relative;
}

The border now looks like this:

Opening Image

We can use the pseudo-class before and its border-top to set a "horizontal":

.add::before{
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 80px;
  margin-left: -40px;
  margin-top: -5px;
  border-top: 10px solid;
}

Note that we used absolute positioning. Now it becomes like this:

Add horizontal

Referring to the above, we can use the after pseudo-class and border-bottom to set a "vertical":

.add::after {
 content: '';
 position: absolute;
 left: 50%;
 top: 50%;
 height: 80px;
 margin-left: -5px;
 margin-top: -40px;
 border-left: 10px solid;
}

Add the hover pseudo-class and set the color when the mouse is hovering:

.add:hover {
  color: blue;
}

The final style:

finally-picture

When the mouse hovers over it, it changes color:

change-color

You can view the effect here:

https://jsbin.com/quvidap/edit?html,css,output

Summarize

The above is the example code of how to use CSS to achieve the "plus sign" effect. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  js to realize payment countdown and return to the home page

>>:  Select web page drop-down list and div layer covering problem

Recommend

Solve the problem of case sensitivity of Linux+Apache server URL

I encountered a problem today. When entering the ...

Sample code for JS album image shaking and enlarging display effect

The previous article introduced how to achieve a ...

How to use React to implement image recognition app

Let me show you the effect picture first. Persona...

Summary of the use of element's form elements

There are many form elements. Here is a brief sum...

VM VirtualBox virtual machine mount shared folder

One environment Install VMware Tools on CentOS 7 ...

Detailed analysis of javascript data proxy and events

Table of contents Data Brokers and Events Review ...

Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin to work with Apache on...

The complete usage of setup, ref, and reactive in Vue3 combination API

1. Getting started with setUp Briefly introduce t...

Html long text automatically cuts off when it exceeds the tag width

When we display long text, we often need to interc...

When backing up files in Centos7, add the backup date to the backup file

Linux uses files as the basis to manage the devic...

Two methods to disable form controls in HTML: readonly and disabled

In the process of making web pages, we often use f...

Customization Method of Linux Peripheral File System

Preface Generally speaking, when we talk about Li...

Example code for implementing ellipse trajectory rotation using CSS3

Recently, the following effects need to be achiev...

How to solve the mysql insert garbled problem

Problem description: When inserting Chinese chara...