close button css

PHPz
Release: 2023-05-27 10:11:10
Original
1123 people have browsed it

How to Implement a Beautiful Close Button CSS

The close button is a very basic element, but there are many ways to make it stand out in your website or app design. In this article, we will explore some CSS tips for creating beautiful and eye-catching close buttons.

  1. Set the basic style

For most close buttons, you will need to use a round div element to create the basic shape. You can then style it with some CSS, for example:

.close {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #ccc;
  cursor: pointer;
}
Copy after login

This will create a 16 pixel round close button with a gray background color. Note that we also added a pointer CSS property to change the mouse pointer style so that the user can see this element is clickable.

  1. Add a close icon

To make the close button more recognizable, you can add a standard "x" shape. You can create this shape using CSS to generate a pseudo-element, for example:

.close::before, .close::after {
  content: "";
  position: absolute;
  height: 2px;
  width: 10px;
  background-color: #fff;
}

.close::before {
  transform: rotate(45deg);
}

.close::after {
  transform: rotate(-45deg);
}
Copy after login

This will add an up-and-down "x" sign to the close button, making it easier to identify.

  1. Add interactive actions

When the user moves the mouse over the close button, you may want to add some interactive effects to increase its operability. For example, you can use a CSS transition animation to add a color effect:

.close:hover {
  background-color: #aaa;
  transition: background-color 0.2s ease-in-out;
}
Copy after login

This will change the background color when the mouse is hovering over the close button, and use a 0.2 second transition animation to make the color change smoothly.

  1. Adapt to different scenarios

In addition to the basic round close button, you may want to create another style for specific scenarios in your application. For example, in a modal window, you might want a larger close button so users can find it easily. You can use some basic CSS tricks to create different styles.

.close-modal {
  font-size: 24px;
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 50%;
  background-color: #ccc;
  cursor: pointer;
}

.close-modal::before, .close-modal::after {
  content: "";
  position: absolute;
  height: 3px;
  width: 18px;
  background-color: #fff;
}

.close-modal::before {
  transform: rotate(45deg);
  top: 13px;
}

.close-modal::after {
  transform: rotate(-45deg);
  top: 13px;
}
Copy after login

This will create a larger, more prominent close button and change the icon color to white so it is easier to identify.

Summary

The close button is an essential element in any application, but you can use CSS tricks to make it stand out. By creating a basic style and adding interactivity to it, you can create a powerful and eye-catching close button. It can be adjusted and modified as needed to suit different scenarios and use cases.

The above is the detailed content of close button css. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template