I have a div
container on my web page with fixed width and it contains form elements for logging in. Below these elements there are a submit button, forgotten password link etc.
It happens the last line elements need fewer width than the box provides. How to spread them evenly? I don't want
| A B C |
| A B C |
| A | B | C |
Instead I am looking for some CSS way to achieve:
| A B C |
That is:
edit: This answer worked best. I created templates for 2 or 3 elements like this:
div.spread2evenly > div { display: inline-block; *display: inline; /* For IE7 */ zoom: 1; /* Trigger hasLayout */ width: 50%; text-align: center; }
Select the elements in question, and choose the menu item Edit > Other > Space evenly (horizontal) or Edit > Other > Space evenly (vertical). EPLAN determines the distance between the first and last elements and distributes all the others evenly between them.
Center Align Elements To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
Use justify-content: space-between to evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge. Alternatively, use justify-content: space-around to distribute the children with space around them, instead of between them.
CSS3 flexboxes have better browser support now, although you may need to add additional vendor prefixes for more browser coverage.
Just change the display
of the container element to flex
and then utilize the justify-content
property to specify how the browser should distribute the space around and between the flex items along the main axis.
In the example below, you will notice that justify-content: space-around
or justify-content: space-between
are used to space the elements out evenly.
.container { display: flex; } .container.space-around { justify-content: space-around; } .container.space-between { justify-content: space-between; }
<p>Using <code>justify-content: space-around</code>:</p> <div class="container space-around"> <div>A</div> <div>B</div> <div>C</div> </div> <hr /> <p>Using <code>justify-content: space-between</code>:</p> <div class="container space-between"> <div>A</div> <div>B</div> <div>C</div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With