【Alignments】
Buttons alignments, zigzag layouts, etc.!
If there isn't enough space for the buttons to align horizontally, the buttons will wrap to the next line
Button 1 Button 2 Button 3 Button 4 Button 5<div class="btns"> <a href="#" class="btn">Button 1</a> <a href="#" class="btn">Button 2</a> <a href="#" class="btn gray">Button 3</a> <a href="#" class="btn">Button 4</a> <a href="#" class="btn">Button 5</a> </div>Copied!.btns { display: flex; flex-wrap: wrap; /* Enable wrapping */ justify-content: center; /* Position the buttons */ gap: 10px; /* Space between the buttons */ } .btn { display: block; padding: 15px 30px; background-color: skyblue; border-radius: 8px; color: white; /* Text color */ text-decoration: none; text-align: center; /* Center-align text inside the button */ cursor: pointer; } .btn:hover { background-color: deepskyblue; /* Change background color on hover */ } /* Styling for specific button */ .gray { background-color: gray; /* Set custom background color */ } .gray:hover { background-color: black; /* Change background on hover */ }Copied!Copied!
-
✅ The child elements of display: flex; are neither block nor inline elements but become "flex items"!
✅ By default, they shrink to fit the content's width (unlike block elements, which typically occupy the full width of the parent element).
✅ When flex: 1; is specified, they expand to fill the remaining space.
That is how bunnies rule.
<div class="display-container"> <div class="zigzag-container"> <div class="row"> <img src="your-picture.jpg" alt="picture"> <p class="text">Your text</p> </div> <div class="row"> <img src="your-picture.jpg" alt="picture"> <p class="text">Your text</p> </div> <div class="row"> <img src="your-picture.jpg" alt="picture"> <p class="text">Your text</p> </div> <div class="row"> <img src="your-picture.jpg" alt="picture"> <p class="text">Your text</p> </div> </div> </div>Copied!.container { display: flex; flex-direction: column; gap: 0px; /* Spacing between rows */ max-width: 800px; /* Content width */ margin: 0 auto; /* Center the entire container */ } .row { display: flex; align-items: flex-start; /* Align text at the top. Use "center" for central alignment */ gap: 20px; /* Space between the image and text */ padding: 5px; } .row:nth-child(odd) { flex-direction: row; /* Odd rows: Image on the left, text on the right */ background-color: #FFF0F5; /* Background color*/ } .row:nth-child(even) { flex-direction: row-reverse; /* Even rows: Image on the right, text on the left */ background-color: #e8fff0; /* Background color*/ } .row img { max-width: 100px; /* Limit image size */ height: auto; border-radius: 8px; /* Rounded corners */ padding: 3px; } .text { margin: 0; padding: 5px; font-size: 16px; line-height: 1; text-align: left; flex: 1; /* Stretch to the width of the parent element */ }Copied!Copied!