CSS-tekstdekoration


Indholdsfortegnelse

    Vis indholdsfortegnelse


Tekst dekoration

I dette kapitel lærer du om følgende egenskaber:

  • text-decoration-line
  • text-decoration-color
  • text-decoration-style
  • text-decoration-thickness
  • text-decoration

Tilføj en dekorationslinje til tekst

Egenskaben text-decoration-line bruges til at tilføje en dekorationslinje til tekst.

Tip: Du kan kombinere mere end én værdi, f.eks. overline og understreg for at vise linjer både over og under en tekst.

Eksempel

h1 {
  text-decoration-line: overline;
}

h2 {
  text-decoration-line: line-through;
}

h3 {
  text-decoration-line: underline;
}
p {
  text-decoration-line: 
  overline underline;
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  text-decoration: overline;
}

h2 {
  text-decoration: line-through;
}

h3 {
  text-decoration: underline;
}

p.ex {
  text-decoration: overline underline;
}
</style>
</head>
<body>

<h1>Overline text decoration</h1>
<h2>Line-through text decoration</h2>
<h3>Underline text decoration</h3>
<p class="ex">Overline and underline text decoration.</p>

<p><strong>Note:</strong> It is not recommended to underline text that is not a link, as this often confuses 
the reader.</p>

</body>
</html>


Bemærk: Det anbefales ikke at understrege tekst, der ikke er et link, da dette ofte forvirrer læseren.


Angiv en farve til dekorationslinjen

Egenskaben text-decoration-color bruges til sæt farven på dekorationslinjen.

Eksempel

h1 {
  text-decoration-line: overline;
  text-decoration-color: 
  red;
}

h2 {
  text-decoration-line: line-through;
  text-decoration-color: 
  blue;
}

h3 {
  text-decoration-line: underline;
  text-decoration-color: 
  green;
}
p {
  text-decoration-line: 
  overline underline;
  text-decoration-color: purple;
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  text-decoration-line: overline;
  text-decoration-color: red;
}

h2 {
  text-decoration-line: line-through;
  text-decoration-color: blue;
}

h3 {
  text-decoration-line: underline;
  text-decoration-color: green;  
}

p {
  text-decoration-line: overline underline;
  text-decoration-color: purple;  
}
</style>
</head>
<body>

<h1>Overline text decoration</h1>
<h2>Line-through text decoration</h2>
<h3>Underline text decoration</h3>
<p>Overline and underline text decoration.</p>

</body>
</html>




Angiv en stil til dekorationslinjen

Egenskaben text-decoration-style bruges til sæt stilen på dekorationslinjen.

Eksempel

 h1 {
  text-decoration-line: underline;
  text-decoration-style: 
  solid;
}
  
h2 {
  text-decoration-line: underline;
  
  text-decoration-style: double;
}
  
h3 {
  text-decoration-line: underline;
  
  text-decoration-style: dotted; 
}
p.ex1 {
  text-decoration-line: underline;
  
  text-decoration-style: dashed; 
}
p.ex2 {
  text-decoration-line: underline;
  
  text-decoration-style: wavy; 
}
p.ex3 {
  text-decoration-line: 
  underline;
  text-decoration-color: red; 
  
  text-decoration-style: wavy; 
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  text-decoration-line: underline;
  text-decoration-style: solid; /* this is default */
}

h2 {
  text-decoration-line: underline;
  text-decoration-style: double;
}

h3 {
  text-decoration-line: underline;
  text-decoration-style: dotted;  
}

p.ex1 {
  text-decoration-line: underline;
  text-decoration-style: dashed;  
}

p.ex2 {
  text-decoration-line: underline;
  text-decoration-style: wavy;  
}

p.ex3 {
  text-decoration-line: underline;
  text-decoration-color: red;  
  text-decoration-style: wavy;  
}
</style>
</head>
<body>

<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p class="ex1">A paragraph.</p>
<p class="ex2">Another paragraph.</p>
<p class="ex3">Another paragraph.</p>

</body>
</html>



Angiv tykkelsen for dekorationslinjen

Egenskaben text-decoration-thickness bruges til indstil tykkelsen på dekorationslinjen.

Eksempel

 h1 {
  text-decoration-line: underline;
  
  text-decoration-thickness: auto;
}
h2 {
  text-decoration-line: 
  underline;
  text-decoration-thickness: 5px;
}
h3 {
  
  text-decoration-line: underline;
  text-decoration-thickness: 25%;
  }
p {
  
  text-decoration-line: underline;
  text-decoration-color: red; 
  
  text-decoration-style: double;
  text-decoration-thickness: 5px; 
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  text-decoration-line: underline;
  text-decoration-thickness: auto;  /* this is default */
}

h2 {
  text-decoration-line: underline;
  text-decoration-thickness: 5px;
}

h3 {
  text-decoration-line: underline;
  text-decoration-thickness: 25%;
}

p {
  text-decoration-line: underline;
  text-decoration-color: red;  
  text-decoration-style: double;
  text-decoration-thickness: 5px;  
}
</style>
</head>
<body>

<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p>A paragraph.</p>

</body>
</html>



Stenografiejendommen

Egenskaben text-decoration er en stenografi ejendom til:

  • text-decoration-line (påkrævet)

  • tekst-dekorationsfarve (valgfrit)

  • tekst-dekorationsstil (valgfrit)

  • tekst-decoration-thickness (valgfrit)

Eksempel

 h1 {
  text-decoration: underline;
}
h2 {
  
  text-decoration: underline red;
}
h3 {
  text-decoration: underline 
  red double;
}
p {
  
  text-decoration: underline red double 5px;
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  text-decoration: underline;
}

h2 {
  text-decoration: underline red;
}

h3 {
  text-decoration: underline red double;
}

p {
  text-decoration: underline red double 5px;
}
</style>
</head>
<body>

<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p>A paragraph.</p>

</body>
</html>



Et lille tip

Alle links i HTML er som standard understreget. Nogle gange dig se, at links er stylet uden understregning. tekstdekorationen: none; bruges til at fjerne understregningen fra links, sådan her:

Eksempel

a {
  text-decoration: none;
}

Prøv det selv →

<!DOCTYPE html>
<html>
<head>
<style>
a {
  text-decoration: none;
}
</style>
</head>
<body>

<h1>Using text-decoration: none</h1>

<p>A link with no underline: <a href="https://www.w3schools.com">W3Schools.com</a></p>

</body>
</html>



Alle CSS-tekstdekorationsegenskaber

text-decoration

Indstiller alle tekst-dekorationsegenskaber i én erklæring

text-decoration-color

Angiver farven på tekstdekorationen

text-decoration-line

Angiver typen af tekstdekoration, der skal bruges (understregning, overstregning, etc.)

text-decoration-style

Angiver stilen for tekstdekorationen (fast, prikket osv.)

text-decoration-thickness

Angiver tykkelsen af tekstdekorationslinjen