Alignment in Flexbox
Flexbox offers a number of alignment-related attributes. These consist of align-items for cross-axis alignment, justify-content for main-axis alignment, and align-content to manage line spacing. It is simple to center, equally space, or align things to one end of the container thanks to these features.
Code Sample
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Flexbox Alignment</title> <style> .flex-container { display: flex; height: 200px; background-color: LightBlue; justify-content: space-around; /* Align items along the main axis */ align-items: center; /* Align items along the cross axis */ } .flex-item { background-color: Coral; padding: 20px; font-size: 20px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item">Item 1</div> <div class="flex-item">Item 2</div> <div class="flex-item">Item 3</div> </div> </body> </html> |
Explanation of code
HTML structure
CSS Styling
Alignment in Flexbox
Flexbox offers a number of alignment-related attributes. These consist of align-items for cross-axis alignment, justify-content for main-axis alignment, and align-content to manage line spacing. It is simple to center, equally space, or align things to one end of the container thanks to these features.
Code Sample
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Flexbox Alignment</title> <style> .flex-container { display: flex; height: 200px; background-color: LightBlue; justify-content: space-around; /* Align items along the main axis */ align-items: center; /* Align items along the cross axis */ } .flex-item { background-color: Coral; padding: 20px; font-size: 20px; } </style> </head> <body> <div class="flex-container"> <div class="flex-item">Item 1</div> <div class="flex-item">Item 2</div> <div class="flex-item">Item 3</div> </div> </body> </html> |
Explanation of code
HTML structure
CSS Styling
Copyrights © 2024 letsupdateskills All rights reserved