How to Create a Border Overlay for a Child Div with Pseudo Elements?

Mary-Kate Olsen
Release: 2024-11-20 18:15:16
Original
355 people have browsed it

How to Create a Border Overlay for a Child Div with Pseudo Elements?

Creating a Border Overlay Child Div

To create a border overlay effect for a child div, you can consider utilizing pseudo elements. This approach offers several advantages:

  • Avoids the need for additional markup.
  • Enhances control over border position and size.

Implementation Example:

body {
  background: grey;
}

.button {
  background: #94c120;
  width: 200px;
  height: 50px;
  margin: 50px;
  position: relative;
}

.button:before {
  content: "";
  position: absolute;
  top: -15px;
  left: -15px;
  width: 100%;
  height: 100%;
  border: 5px solid #fff;
  box-sizing: border-box;
}
Copy after login
<div class="button">
  some text
</div>
Copy after login

The above is the detailed content of How to Create a Border Overlay for a Child Div with Pseudo Elements?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template