I’ve created a grid with inside several items.
Each item could have a different height. Inside each item, I’d like to have a text aligned in the bottom, but I’m not able to do that.
This is the code I used:
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 my-6 mx-6">
<a href="{{ route('recipe.show', $recipe) }}" class="rounded-xl bg-white p-3 shadow-lg hover:shadow-xl">
<div class="relative flex items-end overflow-hidden rounded-xl">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/14/Volleyball_block.jpg/440px-Volleyball_block.jpg" />
</div>
<div class="mt-1 p-2">
<h2 class="text-slate-700">Il muro può essere eseguito da uno o più giocatori (muro collettivo)</h2>
<div class="mt-3 flex items-end justify-between">
<p class="group inline-flex">
<span class="text-slate-400 text-lg pr-2">
<i class="far fa-heart"></i>
</span>
<span class="text-lg font-bold text-orange-500 mr-3">4</span>
</p>
<p class="group inline-flex">
<span class="text-lg font-bold text-orange-500 pr-2">4</span>
<span class="text-slate-400 text-lg">
<i class="far fa-heart"></i>
</span>
</p>
</div>
</div>
</a>
<a href="{{ route('recipe.show', $recipe) }}" class="rounded-xl bg-white p-3 shadow-lg hover:shadow-xl">
<div class="relative flex items-end overflow-hidden rounded-xl">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/14/Volleyball_block.jpg/440px-Volleyball_block.jpg" />
</div>
<div class="mt-1 p-2">
<h2 class="text-slate-700">Il muro</h2>
<div class="mt-3 flex items-end justify-between">
<p class="group inline-flex">
<span class="text-slate-400 text-lg pr-2">
<i class="far fa-heart"></i>
</span>
<span class="text-lg font-bold text-orange-500 mr-3">4</span>
</p>
<p class="group inline-flex">
<span class="text-lg font-bold text-orange-500 pr-2">4</span>
<span class="text-slate-400 text-lg">
<i class="far fa-heart"></i>
</span>
</p>
</div>
</div>
</a>
<a href="{{ route('recipe.show', $recipe) }}" class="rounded-xl bg-white p-3 shadow-lg hover:shadow-xl">
<div class="relative flex items-end overflow-hidden rounded-xl">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/14/Volleyball_block.jpg/440px-Volleyball_block.jpg" />
</div>
<div class="mt-1 p-2">
<h2 class="text-slate-700">Il muro può essere eseguito da uno o più giocatori. Il muro può essere eseguito da uno o più giocatori.</h2>
<div class="mt-3 flex items-end justify-between">
<p class="group inline-flex">
<span class="text-slate-400 text-lg pr-2">
<i class="far fa-heart"></i>
</span>
<span class="text-lg font-bold text-orange-500 mr-3">4</span>
</p>
<p class="group inline-flex">
<span class="text-lg font-bold text-orange-500 pr-2">4</span>
<span class="text-slate-400 text-lg">
<i class="far fa-heart"></i>
</span>
</p>
</div>
</div>
</a>
</div>
and this is result:
result
I’d like to have in each item, the last row aligned in the bottom.
could you tell me what I’m wrong?
thanks
3
Answers
I don’t know if this could help, but can you try adding a css?
Add like below.
You could use grid on your cards. Give the card two rows: one on top for the image that is only as big as its content and the remainder is the text portion of the card.
Then you can set the text portion can be set to flex in the column direction. Using
justify-content: space-between
(justify-between
Tailwind class) will push the "likes" to the bottom of the card:Optionally, you can make all of the images be the same size using
aspect-ratio
andobject-fit
:Working Snippet
You need to play with
flex
flex-1
accross element.Tailwind-play
Structure to follow
Output: