Aller au contenu

Propriété CSS background-clip

La propriété CSS background-clip définit la zone dans laquelle les background-color et background-image sont peints. Si l'élément n'a pas de background-color ou de background-image, cette propriété n'a aucun effet visuel.

La propriété background-clip fait partie des propriétés CSS3.

Pour découper un arrière-plan sur du texte, une version préfixée par le fournisseur (-webkit-background-clip) est également disponible.

Valeur initialeborder-box
S'applique àTous les éléments. S'applique également à ::first-letter et ::first-line.
HéritéeNon.
AnimableNon.
VersionCSS3
Syntaxe DOMobject.style.backgroundClip = "content-box";

Syntaxe

Syntaxe de la propriété CSS background-clip

css
background-clip: border-box | padding-box | content-box | text | initial | inherit;

Exemple de la propriété background-clip :

Exemple de la propriété CSS background-clip avec la valeur content-box

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        border: 3px solid #666;
        padding: 15px;
        background: #ccc;
        background-clip: content-box;
      }
    </style>
  </head>
  <body>
    <h2>Background-clip property example</h2>
    <p>Here the "content-box" value is used.</p>
    <div id="example">
      <p>The background extends to the edge of the content box.</p>
    </div>
  </body>
</html>

Dans l'exemple suivant, observez la différence entre les valeurs "padding-box" et "border-box".

Exemple de la propriété background-clip avec les valeurs "padding-box" et "border-box" :

Exemple de la propriété CSS background-clip avec la valeur border-box

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example1 {
        border: 5px dashed #666;
        padding: 15px;
        background: #1c87c9;
        background-clip: border-box;
      }
      #example2 {
        border: 5px dashed #666;
        padding: 15px;
        background: #1c87c9;
        background-clip: padding-box;
      }
    </style>
  </head>
  <body>
    <h2>Background-clip property example</h2>
    <p>Here the background-clip is set to "border-box" (this is the default value).</p>
    <div id="example1">
      <p>The background extends behind the border.</p>
    </div>
    <p>Here the background-clip is set to "padding-box".</p>
    <div id="example2">
      <p>The background extends to the inside edge of the border.</p>
    </div>
  </body>
</html>

Dans cet exemple, l'arrière-plan est peint à l'intérieur du texte au premier plan.

Propriété CSS background-clip

Exemple de la propriété background-clip avec la valeur "text" :

Exemple de la propriété CSS background-clip avec la valeur text

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        border: 3px dashed #1ebf42;
        padding: 15px;
        background: #1c87c9;
        background-clip: text;
        -webkit-background-clip: text;
        color: transparent;
      }
    </style>
  </head>
  <body>
    <h2>Background-clip property example</h2>
    <p>Here the background-clip is set to "text"</p>
    <div id="example">
      <p>The background is painted within the foreground text.</p>
    </div>
  </body>
</html>

Valeurs

ValeurDescriptionTester »
border-boxL'arrière-plan apparaît derrière la bordure. Il s'agit de la valeur par défaut.Tester »
padding-boxL'arrière-plan apparaît à l'intérieur de la bordure.Tester »
content-boxL'arrière-plan s'étend jusqu'au bord de la boîte de contenu.Tester »
textL'arrière-plan est peint à l'intérieur du texte au premier plan.Tester »
initialDéfinit la propriété à sa valeur par défaut.Tester »
inheritHérite la propriété de son élément parent.

Pratique

Parmi les valeurs suivantes, laquelle peut être utilisée avec la propriété 'background-clip' en CSS ?

Trouvez-vous cela utile?

Aperçu dual-run — comparez avec les routes Symfony en production.