QP School

Full Version: CSS Box Decoration Break
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Description:

The box-decoration-break property allows you to control how backgrounds, borders, and box shadows behave when an element is broken across multiple lines.

Example:

<!DOCTYPE html>
<html>
<head>
  <title>CSS Box Decoration Break Example</title>
  <style>
    .decorated-text {
      background-color: lightblue;
      padding: 10px;
      border: 2px solid red;
      box-shadow: 5px 5px 5px grey;
      box-decoration-break: clone;
      /* OR use 'slice' value for different effect */
      /* box-decoration-break: slice; */
    }
  </style>
</head>
<body>
  <p class="decorated-text">This is a long text that wraps across multiple lines and the box decoration remains consistent.</p>
</body>
</html>

Explanation:

In this example, the .decorated-text paragraph has a background color, padding, border, and box shadow applied to it. By default, when text wraps across multiple lines, the box decorations are repeated for each line. The box-decoration-break: clone property ensures that the box decorations remain consistent even when the element breaks across lines.