_  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _ 
|_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_|
|_|                                                                        |_|
|_|               ,                                                        |_|
|_|             /'/      /'                /'                         /'   |_|
|_|           /' /     /'              --/'-- /'                    /'     |_|
|_|        ,/'  /    /'__     ____     /' ____    ,____     _____,/' ____  |_|
|_|       /`--,/   /'    )  /'    )--/' /'    )--/'    )  /'    /' /'    ) |_|
|_|     /'    /  /'    /'  '---,   /' /'    /' /'    /' /'    /' /(___,/'  |_|
|_| (,/'     (_,(___,/(__(___,/   (__(___,/' /'    /(__(___,/(__(________  |_|
|_|                                                                        |_|
|_|                                                                        |_|
|_|                                                                        |_|
|_|               _                                                        |_|
|_|             /' `\                             /'                       |_|
|_|           /'     )    /'                    /'                         |_|
|_|         /' (___,/'____    ,____     _____,/' ____      ____            |_|
|_|       /'   ;    /'    )--/'    )  /'    /' /'    )   )'    )--         |_|
|_|     /'    /'  /'    /' /'    /' /'    /' /(___,/'  /'                  |_|
|_| (,/'     (_, (___,/' /'    /(__(___,/(__(________/'                    |_|
|_| _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _ |_|
|_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_|

CSS Basics: Abstände und Ränder

Diese Seite zeigt einige grundlegende CSS-Eigenschaften. Klicke rechts auf eine CSS-Zeile – links in der Vorschau siehst du das Ergebnis.


Außenabstand (margin)

Legt den Außenabstand fest, also den Abstand um die Box herum. Die gelbe Box schrumpft, weil der Außenabstand Platz im grauen Elternelement braucht.

Jede Seite lässt sich einzeln einstellen: margin-top (oben), margin-right (rechts), margin-bottom (unten) und margin-left (links). Mit der Kurzschreibweise margin geht es in einer Zeile:

Vorschau

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

CSS

margin: 0; margin-top: 60px; margin-right: 60px; margin-bottom: 60px; margin-left: 60px; margin: 30px; margin: 10px 60px; margin: 10px 30px 60px 90px;

Innenabstand (padding)

Legt den Innenabstand fest, also den Abstand zwischen dem Rand der Box und ihrem Inhalt: Der Text rückt vom Rand weg. Die Box selbst bleibt gleich groß und gelb.

Auch hier gibt es padding-top, padding-right, padding-bottom und padding-left – und die Kurzschreibweise padding mit 1, 2 oder 4 Werten, genau wie bei margin.

Vorschau

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

CSS

padding: 0; padding-top: 60px; padding-right: 60px; padding-bottom: 60px; padding-left: 60px; padding: 30px; padding: 10px 60px; padding: 10px 30px 60px 90px;

Rahmen (border)

Zeichnet einen Rahmen um die Box. Ein Rahmen hat drei Einstellungen:

Die Kurzschreibweise border fasst alle drei zusammen: border: Breite Linienart Farbe;. Mit border-top, border-right, border-bottom und border-left bekommt nur eine Seite einen Rahmen.

Vorschau

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

CSS

border: none; border: 2px solid black; border: 20px solid black; border: 10px dashed black; border: 10px dotted black; border: 20px double black; border: 30px ridge yellow; border: 10px solid red; border-width: 10px;
border-style: solid;
border-color: blue;
border-top: 20px solid red; border-left: 20px solid red;
border-bottom: 10px dashed blue;

border-radius

Rundet die Ecken der Box ab. Je größer der Wert, desto runder die Ecke. Bei einer quadratischen Box ergibt 50% einen Kreis.

Mit 4 Werten bekommt jede Ecke einen eigenen Radius: oben links, oben rechts, unten rechts, unten links – wieder im Uhrzeigersinn. Einzelne Ecken gehen auch mit z. B. border-top-left-radius.

Vorschau

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

CSS

border-radius: 0; border-radius: 10px; border-radius: 60px; border-radius: 50%; border-radius: 0 30px 60px 120px; border-top-left-radius: 120px;




Alles kombiniert