CSS-Flexbox-Container


Inhaltsverzeichnis

    Inhaltsverzeichnis anzeigen


Übergeordnetes Element (Container)

Wie wir im vorherigen Kapitel angegeben haben, handelt es sich hierbei um einen flexiblen Container (der blaue Bereich) mit drei flexiblen Elementen:

1

2

3

Der Flex-Container wird flexibel, indem die Eigenschaft display auf gesetzt wird flex:

Beispiel

 .flex-container {
  
  display: flex;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  margin: 10px;
  padding: 20px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>Create a Flex Container</h1>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

<p>A Flexible Layout must have a parent element with the <em>display</em> property set to <em>flex</em>.</p>

<p>Direct child elements(s) of the flexible container automatically becomes flexible items.</p>

</body>
</html>


Die Eigenschaften des Flex-Containers sind:

  • flex-direction
  • flex-wrap
  • flex-flow
  • justify-content
  • align-items
  • align-content


Die Flex-Direction-Eigenschaft

Die Eigenschaft flex-direction definiert, in welche Richtung der Container die Flex-Elemente stapeln möchte.

1

2

3

Beispiel

Der Wert Spalte stapelt die Flex-Elemente vertikal (von oben nach unten):

 .flex-container {
  
  display: flex;
  
  flex-direction: column;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-direction: column;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-direction Property</h1>

<p>The "flex-direction: column;" stacks the flex items vertically (from top to bottom):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert column-reverse stapelt die Flex-Elemente vertikal (jedoch von unten nach oben):

 .flex-container {
  
  display: flex;
  
  flex-direction: column-reverse;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-direction: column-reverse;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-direction Property</h1>

<p>The "flex-direction: column-reverse;" stacks the flex items vertically (but from bottom to top):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der row-Wert stapelt die Flex-Elemente horizontal (von links nach rechts):

 .flex-container {
  
  display: flex;
  
  flex-direction: row;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-direction: row;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-direction Property</h1>

<p>The "flex-direction: row;" stacks the flex items horizontally (from left to right):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert row-reverse stapelt die Flex-Elemente horizontal (jedoch von rechts nach links):

 .flex-container {
  
  display: flex;
  
  flex-direction: row-reverse;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-direction: row-reverse;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-direction Property</h1>

<p>The "flex-direction: row-reverse;" stacks the flex items horizontally (but from right to left):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>



Die Flex-Wrap-Eigenschaft

Die Eigenschaft flex-wrap gibt an, ob die Flex-Elemente umbrochen werden sollen oder nicht.

Die folgenden Beispiele enthalten 12 Flex-Elemente, um den besser zu veranschaulichen flex-wrap-Eigenschaft.

1

2

3

4

5

6

7

8

9

10

11

12

Beispiel

Der Wert wrap gibt an, dass die Flex-Elemente bei Bedarf umbrochen werden:

 .flex-container {
  
  display: flex;
  
  flex-wrap: wrap;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-wrap: wrap;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-wrap Property</h1>

<p>The "flex-wrap: wrap;" specifies that the flex items will wrap if necessary:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

<p>Try resizing the browser window.</p>

</body>
</html>


Beispiel

Der Wert nowrap gibt an, dass die Flex-Elemente nicht umbrochen werden (dies ist Standard):

 .flex-container {
  
  display: flex;
  
  flex-wrap: nowrap;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-wrap: nowrap;
  background-color: DodgerBlue;
}

.flex-container>div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-wrap Property</h1>

<p>The "flex-wrap: nowrap;" specifies that the flex items will not wrap (this is default):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

<p>Try resizing the browser window.</p>

</body>
</html>


Beispiel

Der Wert wrap-reverse gibt an, dass die flexiblen Elemente umbrochen werden ggf. in umgekehrter Reihenfolge:

 .flex-container {
  
  display: flex;
  
  flex-wrap: wrap-reverse;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-wrap: wrap-reverse;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The flex-wrap Property</h1>

<p>The "flex-wrap: wrap-reverse;" specifies that the flex items will wrap if necessary, in reverse order:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

<p>Try resizing the browser window.</p>

</body>
</html>



Die Flex-Flow-Eigenschaft

Die Eigenschaft flex-flow ist eine Abkürzungseigenschaft zum Festlegen beider Flex-Richtung und flex-wrap-Eigenschaften.

Beispiel

 .flex-container {
  
  display: flex;
  
  flex-flow: row wrap;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  flex-flow: row wrap;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>
<h1>The flex-flow Property</h1>

<p>The flex-flow property is a shorthand property for the flex-direction and the flex-wrap properties.</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

<p>Try resizing the browser window.</p>

</body>
</html>



Die justify-content-Eigenschaft

Die Eigenschaft justify-content wird zum Ausrichten der Flex-Elemente verwendet:

1

2

3

Beispiel

Der Wert center richtet die Flex-Elemente in der Mitte des Containers aus:

 .flex-container {
  
  display: flex;
  
  justify-content: center;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: center;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The justify-content Property</h1>

<p>The "justify-content: center;" aligns the flex items at the center of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-start richtet die Flex-Elemente am Anfang des Containers aus (Dies ist die Standardeinstellung):

 .flex-container {
  
  display: flex;
  
  justify-content: flex-start;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: flex-start;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The justify-content Property</h1>

<p>The "justify-content: flex-start;" aligns the flex items at the beginning of the container (this is default):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-end richtet die Flex-Elemente am Ende des Containers aus:

 .flex-container {
  
  display: flex;
  
  justify-content: flex-end;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: flex-end;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The justify-content Property</h1>

<p>The "justify-content: flex-end;" aligns the flex items at the end of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert space-around zeigt die Flex-Elemente mit Leerzeichen vor, zwischen und nach den Zeilen:

 .flex-container {
  
  display: flex;
  
  justify-content: space-around;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: space-around;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The justify-content Property</h1>

<p>The "justify-content: space-around;" displays the flex items with space before, between, and after the lines:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert space-between zeigt die Flex-Elemente mit Leerzeichen dazwischen an Linien:

 .flex-container {
  
  display: flex;
  
  justify-content: space-between;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: space-between;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The justify-content Property</h1>

<p>The "justify-content: space-between;" displays the flex items with space between the lines:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>



Die align-items-Eigenschaft

Die Eigenschaft align-items wird zum Ausrichten der Flex-Elemente verwendet.

1

2

3

In diesen Beispielen verwenden wir einen 200 Pixel hohen Container, um den besser zu veranschaulichen align-items-Eigenschaft.

Beispiel

Der Wert center richtet die Flex-Elemente in der Mitte aus Container:

 .flex-container {
  
  display: flex;
  height: 200px;
  
  align-items: center;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 200px;
  align-items: center;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-items Property</h1>

<p>The "align-items: center;" aligns the flex items in the middle of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-start richtet die Flex-Elemente oben im Container aus:

 .flex-container {
  
  display: flex;
  height: 200px;
  
  align-items: flex-start;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 200px;
  align-items: flex-start;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-items Property</h1>

<p>The "align-items: flex-start;" aligns the flex items at the top of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-end richtet die Flex-Elemente am unteren Rand des Containers aus:

 .flex-container {
  
  display: flex;
  height: 200px;
  
  align-items: flex-end;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 200px;
  align-items: flex-end;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-items Property</h1>

<p>The "align-items: flex-end;" aligns the flex items at the bottom of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert stretch streckt die Flex-Elemente, um den Container zu füllen (Dies ist die Standardeinstellung):

 .flex-container {
  
  display: flex;
  height: 200px;
  
  align-items: stretch;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 200px;
  align-items: stretch;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-items Property</h1>

<p>The "align-items: stretch;" stretches the flex items to fill the container (this is default):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>


Beispiel

Der Wert baseline richtet die Flex-Elemente wie ihre Baselines aus:

 .flex-container {
  
  display: flex;
  height: 200px;
  
  align-items: baseline;
}

Hinweis: Im Beispiel werden unterschiedliche Schriftgrößen verwendet, um zu zeigen, dass die Elemente an der Textgrundlinie ausgerichtet werden:


1

2

3

4

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 200px;
  align-items: baseline;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>
<h1>The align-items Property</h1>

<p>The "align-items: baseline;" aligns the flex items such as their baselines aligns:</p>

<div class="flex-container">
  <div><h1>1</h1></div>
  <div><h6>2</h6></div>
  <div><h3>3</h3></div>  
  <div><small>4</div>  
</div>

</body>
</html>



Die align-content-Eigenschaft

Die Eigenschaft align-content wird zum Ausrichten der Flexlinien verwendet.

1

2

3

4

5

6

7

8

9

10

11

12

In diesen Beispielen verwenden wir einen 600 Pixel hohen Container mit dem flex-wrap-Eigenschaft auf wrap gesetzt, um die align-content-Eigenschaft besser zu veranschaulichen.

Beispiel

Der Wert space-between zeigt die Flexlinien mit gleichem Abstand zwischen ihnen an:

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: space-between;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: space-between;
  overflow: scroll;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: space-between;" displays the flex lines with equal space between them:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>


Beispiel

Der Wert space-around zeigt die Flexlinien mit Leerzeichen davor an. zwischen und nach ihnen:

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: space-around;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: space-around;
  overflow: scroll;  
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: space-around;" displays the flex lines with space before, between, and after them:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>


Beispiel

Der Wert stretch streckt die Flexlinien, um den Rest einzunehmen Leerzeichen (dies ist die Standardeinstellung):

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: stretch;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: stretch;
  overflow: scroll;  
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: stretch;" stretches the flex lines to take up the remaining space (this is default):</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>


Beispiel

Der Wert center zeigt die Flexlinien in der Mitte des Containers an:

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: center;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: center;
  overflow: scroll;  
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: center;" displays the flex lines in the middle of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-start zeigt die Flexlinien am Anfang des Containers an:

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: flex-start;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: flex-start;
  overflow: scroll;  
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: flex-start;" displays the flex lines at the start of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>


Beispiel

Der Wert flex-end zeigt die Flexlinien am Ende des Containers an:

 .flex-container {
  
  display: flex;
  height: 600px;
  
  flex-wrap: wrap;
  
  align-content: flex-end;
}

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: flex-end;
  overflow: scroll;  
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The align-content Property</h1>

<p>The "align-content: flex-end;" displays the flex lines at the end of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
  <div>9</div>  
  <div>10</div>
  <div>11</div>
  <div>12</div>  
</div>

</body>
</html>



Perfekte Zentrierung

Im folgenden Beispiel lösen wir ein sehr häufiges Stilproblem: die perfekte Zentrierung.

LÖSUNG: Setzen Sie die Eigenschaften justify-content und align-items auf center, und das Flex-Element wird perfekt zentriert:

Beispiel

 .flex-container {
  display: flex;
  height: 300px;
  justify-content: 
  center;
  align-items: center;
}
 

Probieren Sie es selbst aus →

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  color: white;
  width: 100px;
  height: 100px;
}
</style>
</head>
<body>

<h1>Perfect Centering</h1>

<p>A flex container with both the justify-content and the align-items properties set to <em>center</em> will align the item(s) in the center (in both axis).</p>

<div class="flex-container">
  <div></div>
</div>

</body>
</html>



Die CSS-Flexbox-Containereigenschaften

In der folgenden Tabelle sind alle Eigenschaften des CSS-Flexbox-Containers aufgeführt:

align-content

Ändert das Verhalten der Flex-Wrap-Eigenschaft. Es ähnelt align-items, aber anstatt Flex-Elemente auszurichten, richtet es Flex-Linien aus

align-items

Richtet die flexiblen Elemente vertikal aus, wenn die Elemente nicht den gesamten verfügbaren Platz auf der Querachse nutzen

display

Gibt den Boxtyp an, der für ein HTML-Element verwendet wird

flex-direction

Gibt die Richtung der flexiblen Elemente in einem Flex-Container an

flex-flow

Eine Abkürzung für Flex-Direction und Flex-Wrap

flex-wrap

Gibt an, ob die Flex-Elemente umgebrochen werden sollen oder nicht, wenn auf einer Flex-Linie nicht genügend Platz für sie vorhanden ist

justify-content

Richtet die Flex-Elemente horizontal aus, wenn die Elemente nicht den gesamten verfügbaren Platz auf der Hauptachse nutzen