I have a div block which does not have a fixed width.
Inside, I have an <ul> <li>..</li>
block with 11 items.
I would like these <li>
items to be listed inside the div, all with equal widths like this:
##item## ##item## ##item##
##item## ##item## ##item##
##item## ##item## ##item##
##item## ##item##
However, I can't sort it out at all.
I tried float left and right but the central 3 elements will not be centered.
What can I do to get this working?
Thanks!
With CSS grid layout, the grid itself within its container as well as grid items can be positioned with the following 6 properties: justify-items , align-items , justify-content , align-content , justify-self , and align-self .
Using the property grid-auto-flow with a value of column . In this case grid will add items in rows that you have defined using grid-template-rows . When it fills up a column it will move onto the next explicit column, or create a new column track in the implicit grid.
The "Inline Blocks" link that Jordan posted is a great resource, particularly when it comes to older browser support. For quick reference for others landing on this page off of google, the basic css for creating a centered, inline-block grid is:
ul {
margin: 0 auto;
text-align: center;
}
li {
display: inline-block;
vertical-align: top;
}
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