Zum Inhalt springen

CSS-Eigenschaft margin-bottom

Die Eigenschaft margin-bottom dient dazu, den Außenabstand am unteren Rand eines Elements festzulegen.

INFO

Negative Werte sind gültig.

INFO

Wenn nicht ersetzte Inline-Elemente (wie <tt> oder <span>) verwendet werden, hat die CSS-Eigenschaft margin-bottom keine Auswirkung.

Anfangswert0
Gilt fürAlle Elemente. Gilt auch für ::first-letter.
VererbbarNein.
AnimierbarJa. Der untere Außenabstand des Elements ist animierbar.
VersionCSS2
DOM-Syntaxobject.style.marginBottom = "70px";

Syntax

Syntax der CSS-Eigenschaft margin-bottom

css
margin-bottom: length | auto | initial | inherit;

Beispiel für die margin-bottom-Eigenschaft:

Beispiel für die CSS-Eigenschaft margin-bottom mit px-Wert

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .bottom {
        margin-bottom: 100px;
      }
    </style>
  </head>
  <body>
    <h2>Margin-bottom property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="bottom">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </body>
</html>

Ergebnis

CSS-Eigenschaft margin-bottom

Beispiel für die margin-bottom-Eigenschaft mit dem Wert "4em":

Beispiel für die CSS-Eigenschaft margin-bottom mit em-Wert

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .bottom {
        margin-bottom: 4em;
      }
    </style>
  </head>
  <body>
    <h2>Margin-bottom property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="bottom">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </body>
</html>

Beispiel für die margin-bottom-Eigenschaft mit den Werten "px", "em" und "%":

Beispiel für die CSS-Eigenschaft margin-bottom mit px-, em- und %-Werten

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p.p1 {
        margin-bottom: 5em;
      }
      p.p2 {
        margin-bottom: 20%;
      }
      p.p3 {
        margin-bottom: 20px;
      }
    </style>
  </head>
  <body>
    <h2>Margin-bottom property example</h2>
    <p>A paragraph with no margins specified.</p>
    <p class="p1">Bottom margin is set to 5em.</p>
    <p class="p2">Bottom margin is set to 20%.</p>
    <p class="p3">Bottom margin is set to 20px.</p>
    <p>A paragraph with no margins specified.</p>
  </body>
</html>

Außenabstand-Kollaps

In einigen Fällen können der obere und der untere Außenabstand zu einem einzigen Außenabstand zusammenfallen, der dem größeren der beiden Werte entspricht. Dies tritt nur bei vertikalen Außenabständen (oben und unten) auf.

Außenabstand-Kollaps

css
p.one {
  margin: 20px 0;
}

p.two {
  margin: 35px 0;
}

Im obigen Codebeispiel hat das Element <p class="one"> einen vertikalen Außenabstand von 20px. Das Element <p class="two"> hat einen vertikalen Außenabstand von 35px. Man könnte meinen, der vertikale Abstand zwischen diesen beiden Elementen müsse 55px betragen. Aufgrund des Außenabstand-Kollapses beträgt der tatsächliche Abstand jedoch nur 35px.

Beispiel für einen Außenabstand-Kollaps:

Beispiel für den Außenabstand-Kollaps

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p.one {
        margin: 20px 0;
      }
      p.two {
        margin: 35px 0;
      }
    </style>
  </head>
  <body>
    <h2>Margin-bottom property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="one">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="two">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </body>
</html>

Werte

WertBeschreibungAusführen
autoLegt den unteren Außenabstand fest. Dies ist der Standardwert dieser Eigenschaft.Ausführen »
lengthDefiniert einen unteren Außenabstand in px, pt, cm usw. Standardwert ist 0.Ausführen »
%Legt den unteren Außenabstand in % des Elternelements fest.Ausführen »
initialLegt die Eigenschaft auf ihren Standardwert zurück.Ausführen »
inheritErbt die Eigenschaft von ihrem Elternelement.

Praxis

Welche Funktion hat die Eigenschaft 'margin-bottom' in CSS?

Finden Sie das nützlich?

Dual-run-Vorschau — vergleichen Sie mit den Symfony-Routen live.