Home  >  Article  >  Web Front-end  >  How to Create a Slanted Background with CSS Using Pseudo Elements?

How to Create a Slanted Background with CSS Using Pseudo Elements?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-06 11:00:02841browse

How to Create a Slanted Background with CSS Using Pseudo Elements?

Creating a Slanted Background with CSS

The provided code snippet falls short in achieving the desired slanted background effect due to the limited capabilities of transformation methods like rotate. A more effective approach involves employing pseudo elements with skew transformation.

By implementing this technique, you can create a slanted background as follows:

body {
  height: 100vh;
  margin: 0;
  background: yellow;
}

body:before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 300px;
  background: #000;
  transform: skew(-30deg);
  transform-origin: top;
}

The above is the detailed content of How to Create a Slanted Background with CSS Using Pseudo Elements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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