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

Summary of common MySQL commands

Set change mysqlroot password Enter the MySQL dat...

Website Design Experience Summary of Common Mistakes in Website Construction

Reminder: Whether it is planning, designing, or de...

Div adaptive height automatically fills the remaining height

Scenario 1: Html: <div class="outer"...

Nodejs uses readline to prompt for content input example code

Table of contents Preface 1. bat executes js 2. T...

jQuery implements a simple comment area

This article shares the specific code of jQuery t...

Solution to overflow:hidden failure in CSS

Cause of failure Today, when I was writing a caro...

Linux uses stty to display and modify terminal line settings

Sttty is a common command for changing and printi...

A brief discussion on the principle of React two-way data binding

Table of contents What is two-way data binding Im...

Podman boots up the container automatically and compares it with Docker

Table of contents 1. Introduction to podman 2. Ad...

Analyze the selection problem of storing time and date types in MySQL

In general applications, we use timestamp, dateti...

Ant designing vue table to achieve a complete example of scalable columns

Perfect solution to the scalable column problem o...

The actual process of encapsulating axios in the project

Table of contents Preface Benefits of axios encap...

CSS3 new layout: flex detailed explanation

Flex Basic Concepts Flex layout (flex is the abbr...