Here are five simple examples illustrating the main and cross axes in Flexbox:
### 1. Horizontal Main Axis
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Horizontal Main Axis</title>
<style>
.container {
display: flex; /* Create a flex container */
border: 2px solid #333;
justify-content: space-around; /* Align items along the main axis */
}
.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. Vertical Main Axis
```html
<div class="container" style="flex-direction: column; align-items: center;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>
```
### 3. Horizontal Cross Axis
```html
<div class="container" style="align-items: flex-end;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>
```
### 4. Vertical Cross Axis
```html
<div class="container" style="flex-direction: column; justify-content: flex-end;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>
```
### 5. Reversed Axes
```html
<div class="container" style="flex-direction: column-reverse; align-items: flex-end;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>
```
These examples demonstrate different configurations of flex containers and items to control alignment along the main and cross axes. Experiment with the `justify-content` and `align-items` properties to see how they affect the layout!
0 Comments