CSS
Evenly Distributing Space Around Flex Items with 'space-evenly'
Achieve perfect distribution of space around flex items, ensuring consistent spacing between items and at both ends of the container with 'justify-content: space-evenly'.
.button-group {
display: flex;
justify-content: space-evenly; /* Distributes space evenly around items */
width: 100%;
max-width: 600px;
margin: 20px auto;
padding: 10px;
border: 1px solid #ccc;
background-color: #f9f9f9;
}
.button-group button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.button-group button:hover {
background-color: #0056b3;
}
How it works: The `justify-content: space-evenly` property in Flexbox is used to distribute space evenly between and around flex items along the main axis. Unlike `space-around` or `space-between`, `space-evenly` ensures that the space between any two adjacent items is equal to the space before the first item and after the last item. This creates a visually balanced layout where all items appear to have uniform surrounding space, commonly used for button groups or navigation links.