CoverT 22: background-clip

codeInteractive Code Example

The background-clip property sets what area an element’s background color extends to.

Code

<h4>Border Box (default)</h4>
<div class="my-box border-box"></div>

<h4>Padding Box</h4>
<div class="my-box padding-box"></div>

<h4>Content Box</h4>
<div class="my-box content-box"></div>
.my-box {
  height: 100px;
  width: 100px;
  border: 10px dashed black;
  background-color: pink;
  padding: 20px;
  margin-bottom: 20px;
}

.border-box {
  background-clip: border-box;
}

.padding-box {
  background-clip: padding-box;
}

.content-box {
  background-clip: content-box
}

Results

Border Box (default)

Padding Box

Content Box