Alignment in Flex

Alignment in Flex


Here are five examples illustrating different alignment techniques in Flexbox:

### 1. Center Alignment

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Center Alignment</title>
  <style>
    .container {
      display: flex;
      justify-content: center; /* Center items along the main axis */
      align-items: center; /* Center items along the cross axis */
      height: 200px; /* Just for visualization */
      border: 2px solid #333;
    }
    .item {
      background-color: #f0f0f0;
      padding: 10px;
      margin: 5px;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
  </div>
</body>
</html>
```

### 2. Space Between Alignment

```html
<div class="container" style="justify-content: space-between;">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
```

### 3. Space Around Alignment

```html
<div class="container" style="justify-content: space-around;">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
```

### 4. Flex Start Alignment

```html
<div class="container" style="justify-content: flex-start;">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
```

### 5. Flex End Alignment

```html
<div class="container" style="justify-content: flex-end;">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
```

These examples showcase various alignment techniques using the `justify-content` and `align-items` properties. Experiment with different values and combine them to achieve the desired layout for your projects!

Contact us for software training, education or development










 

Post a Comment

0 Comments

Me