I want to create a card which is pretty simple, and contains only an image, a paragraph and two buttons.
The card I want to create:
<div class="container">
<img src="" alt="">
<p></p>
<button></button>
<button></button>
</div>
.container{
padding: 2rem;
grid-template-columns:[img-start] 120px [img-end content-start] 1fr [content-end];
grid-column-gap: 1.6rem;
grid-template-rows: repeat(2, auto)
}
Then I place my buttons:
button{
grid-column: content;
grid-row: 2/3;
}
.container {
padding: 2rem;
grid-template-columns: [img-start] 120px [img-end content-start] 1fr [content-end];
grid-column-gap: 1.6rem;
grid-template-rows: repeat(2, auto)
}
button {
grid-column: content;
grid-row: 2/3;
}
<div class="container">
<img src="" alt="">
<p></p>
<button></button>
<button></button>
</div>
However, the buttons overlap and aren’t next each other, so I wish to know if there’s a way to place multiple grid-items in the sane grid-area and say that this area is like a flex-row wrapper?
I would have used flexbox with some divs which wrapped the buttons, and assigned this div inside the grid-area, but I want to use grid to gain knowledge of this CSS property. So I wonder if there is a native grid way to do so?
2
Answers
As Chris Barr mentioned, CSS Grid Layout is useful when the content is evenly spread as columns and rows. In this case, You can use Flex as shown below.
If you want to use the grid layout, you need to add another column to fit the second button.
The paragraph should span the 2 last columns and each button should have their own column like this :