Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing double borders in CSS Grid

Tags:

html

css

css-grid

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>
like image 916
klugjo Avatar asked Dec 19 '17 08:12

klugjo


People also ask

How do you avoid double border in CSS?

Add a border-left and border-top to the parent. Add border-right and border-bottom to each of the children.

Why are there gaps in my grid CSS?

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.

How do I get rid of the grid border in CSS?

Add on top of your css before everything else: body { margin: 0; } this will work, I tested it.


1 Answers

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>
like image 63
Michael Benjamin Avatar answered Sep 21 '22 05:09

Michael Benjamin