Beispiel:Box-Modell-2a.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Box-Modell - 2 (Variante)</title>
  <style>
figure {
  width: fit-content;
  margin: 2em auto;
}
figcaption {
  margin-top: 1em;
  text-align: center;
}
.margin-box {
  position: relative;
  background-color: #fcc;
  width: fit-content;
  border: medium dotted red;
}
.margin-box::before {
  content: "margin";
  color: black;
  top: 0.2em;
  right: 0.75em;
}
.box {
  position: relative;
  margin: 1.5em;
  border: 1.5em solid steelblue;
  padding: 1.5em;
  width: 12em;
  height: 3em;
  background: linear-gradient(white), goldenrod;
  background-clip: content-box, padding-box;
}
::before, ::after {
  position: absolute; 
  font-size: 100%;
}
.box::before {
  content: "border";
  color: white;
  top: -1.3em;
  right: -0.75em;
}
.box::after {
  content: "padding";
  color: black;
  top: 0.2em;
  right: 0.75em;
}
  </style>
</head>
<body>
<h1>Visualisierung der Box-Bereiche von CSS</h1>
<figure>
  <div class="margin-box">
    <div class="box">Der weiße Bereich enthält den Inhalt</div>
  </div>
  <figcaption>Das Bild zeigt die verschiedenen<br>Bereiche des Boxmodells.</figcaption>
</figure>
</body>
</html>