Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting grid items to not Overlap when sharing the same row and column

Right now, when two grid items share the same row and column they overlap each over.

<div class="some-grid-container">
    <div style="grid-row: 1; grid-column: 1">Item 1</div>
    <div style="grid-row: 1; grid-column: 1">Item 2</div>
</div>

How do I them not overlap? Probably behave like flex items when sharing the same row and column. (Without making an outer container).

like image 239
jlawcordova Avatar asked Apr 23 '18 06:04

jlawcordova


People also ask

How do you stop the grid overflowing?

Solution, set an explicit minimum not to auto To avoid the minimum width/height calculation size, you should therefore set the minimum width or heigth to another value than auto . And as you can see: the first column does not overflow anymore. the two columns share 50% of the space as specified in the fraction.

Which property will create gaps between the rows in the grid?

The grid-row-gap property defines the size of the gap between the rows in a grid layout. Note: This property was renamed to row-gap in CSS3.


1 Answers

Your syntax is not correct. Inline styles are not using those braces "{", "}". And additionally you need to specify the "Item 2" in the second column. If you use the same row and same column then both divs are in the same place for sure.

Try...

CSS:

.some-grid-container{
  display: grid;
  grid-template-columns: auto;
}

HTML:

<div class="some-grid-container">
    <div style="grid-row: 1; grid-column: 1;">Item 1</div>
    <div style="grid-row: 1; grid-column: 2;">Item 2</div>
</div>

This should create a 100% width grid with 2 equally sized columns.

like image 150
jdickel Avatar answered Oct 02 '22 17:10

jdickel