I’m working on a React component using Tailwind CSS, and I’m trying to achieve a specific layout. I have a div
with an image and two paragraphs inside it. I want the paragraphs to be centered both horizontally and vertically within the div
so that they appear at the center of the image.
Here’s my current code:
<div className="flex flex-col items-center justify-center text-center">
<img src="img/slider1.png" alt="slider1" className="mb-4" />
<p className="font-bold">This paragraph is full of cats</p>
<p>This paragraph is not.</p>
</div>
Despite using items-center
and justify-center
, the text is not aligning exactly at the center of the image. I want both paragraphs to be positioned at the center, both horizontally and vertically, within the div
.
Any suggestions or corrections to my current approach would be greatly appreciated. Thank you!
2
Answers
You can change your code like this. Use an div to wrap it.
Add
h-screen
to the outer div to ensure that it takes the full height of the viewport.Also use an additonal
div
to center the paragraphs both horizontally and vertically.