Aller au contenu

Propriété CSS border-top-color

La propriété border-top-color définit la couleur de la bordure supérieure d'un élément.

Vous pouvez spécifier la couleur de la bordure supérieure, ainsi que les couleurs des bordures inférieure, droite et gauche avec la propriété abrégée border-color.

Si vous utilisez la propriété border-top-color, vous devez d'abord définir les propriétés border-style ou border-top-style, puis modifier la couleur du style défini.

La largeur par défaut d'une bordure est medium. Vous pouvez spécifier la largeur à l'aide des propriétés border-width ou border-top-width.

Valeur initialecurrentColor
S'applique àTous les éléments. S'applique également à ::first-letter.
HéritéeNon
AnimableOui. La couleur de la bordure supérieure est animable.
VersionCSS1
Syntaxe DOMobject.style.borderTopColor = "black";

Syntaxe

Syntaxe de la propriété CSS border-top-color

css
border-top-color: color | transparent | initial | inherit;

Exemple de la propriété border-top-color :

Exemple de la propriété CSS border-top-color

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        width: 300px;
        padding: 20px;
        border-style: solid;
        border-color: #666;
        border-top-color: #1c87c9;
      }
    </style>
  </head>
  <body>
    <h2>Border-top-color example</h2>
    <div>Example for the border-top-color property with different top border color.</div>
  </body>
</html>

Résultat

Propriété CSS border-top-color

Exemple de la propriété border-top-color avec la valeur « transparent » :

Exemple de la propriété CSS border-top-color avec la valeur transparent

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      h2 {
        padding-bottom: 8px;
        text-align: center;
        border: 12px groove #1c87c9;
        border-top-color: transparent;
      }
    </style>
  </head>
  <body>
    <h2>A heading with a transparent top border</h2>
  </body>
</html>

INFO

Les valeurs hexadécimales, RGB, RGBA, HSL, HSLA ou les noms de couleurs peuvent être appliqués comme valeur pour la propriété border-top-color.

Exemple de la propriété border-top-color avec une valeur de couleur nommée :

Exemple de la propriété CSS border-top-color avec la valeur darkred (nom de couleur)

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        padding: 10px;
        width: 50%;
        border: solid #666;
        border-top-color: darkred;
      }
    </style>
  </head>
  <body>
    <div>Border-top-color property with a named color value.</div>
  </body>
</html>

Exemple de la propriété border-top-color avec une valeur hexadécimale :

Exemple de la propriété CSS border-top-color avec une valeur hexadécimale

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        padding: 10px;
        width: 50%;
        border: solid #666;
        border-top-color: #1c87c9;
      }
    </style>
  </head>
  <body>
    <div>Border-top-color property with a hexadecimal value.</div>
  </body>
</html>

Exemple de la propriété border-top-color avec une valeur RGB :

Exemple de la propriété CSS border-top-color avec une valeur RGB

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        padding: 10px;
        width: 50%;
        border: solid #666;
        border-top-color: rgb(142, 191, 66);
      }
    </style>
  </head>
  <body>
    <div>Border-top-color property with a RGB value.</div>
  </body>
</html>

Exemple de la propriété border-top-color avec une valeur HSL :

Exemple de la propriété CSS border-top-color avec une valeur HSL

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        padding: 10px;
        width: 50%;
        border: solid #666;
        border-top-color: hsl(24, 80%, 50%);
      }
    </style>
  </head>
  <body>
    <div>Border-top-color property with a HSL value.</div>
  </body>
</html>

Valeurs

ValeurDescriptionEssayer
colorDéfinit la couleur de la bordure supérieure. La couleur par défaut est celle de l'élément actuel. Les noms de couleurs, les codes hexadécimaux, rgb(), rgba(), hsl(), hsla() peuvent être utilisés. Valeur requise.Essayer »
transparentApplique une couleur transparente à la bordure supérieure. La bordure supérieure occupera toujours l'espace défini par la valeur border-width.Essayer »
initialDéfinit la propriété à sa valeur par défaut.Essayer »
inheritHérite la propriété de son élément parent.

Pratique

À quoi sert la propriété 'border-top-color' en CSS ?

Trouvez-vous cela utile?

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