Given the current CSS grid example, how can I collapse the borders in order to avoid the double borders ?
This is such a simple thing to achieve using an Html table. How do I do it using display: grid
?
.wrapper { display: grid; grid-template-columns: 50px 50px 50px 50px; } .wrapper > div { padding: 15px; text-align: center; border: 1px solid black; }
<div class="wrapper"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </div>
Add a border-left and border-top to the parent. Add border-right and border-bottom to each of the children.
The vertical gaps are caused by the images not filling the vertical space in the grid items. The problem is made worse with align-items: center on the container, which removes the align-items: stretch default. Essentially, there are no gaps between grid items.
Add on top of your css before everything else: body { margin: 0; } this will work, I tested it.
Instead of using an actual border around grid items, use the background color on the container (for "border" color) and the grid-gap
property (for "border" width).
.wrapper { display: inline-grid; grid-template-columns: 50px 50px 50px 50px; border: 1px solid black; grid-gap: 1px; background-color: black; } .wrapper > div { background-color: white; padding: 15px; text-align: center; }
<div class="wrapper"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</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