Tailwind JSx Image wont center on my cards - css

I have made a set of three cards that will display information at the top of the three cards is an image, I am using JSX and Tailwind but can not seem to get the image to center, it sits off to the left.
How do I make it so the image is centered properly what am I missing? staring at it is not helping !
This is my code TIA !
<section>
<div>
<h3 className='text-3xl py-10 text-center'>About Me </h3>
<p className='text-center text-md py-2 leading-8 text-gray-800'>
Blah blah blah <span className="text-teal-500 text-md">Tech</span> blah
</p>
</div>
<div className='lg:flex gap-10 '>
<div className='text-center shadow-lg p-10 rounded-xl my-10'>
<Image src={design} width={100} height={100} />
<h3 className='text-lg font-medium pt-8 pb-2'>Beautiful designs</h3>
<p className='py-2'>
Creating elegant designs suited for your needs
</p>
<h4 className='py-4 text-teal-600'>Design tools I use</h4>
<p className='text-gray-800 py-1'>photoshop</p>
<p className='text-gray-800 py-1'>Aftereffects</p>
<p className='text-gray-800 py-1'>Blender</p>
<p className='text-gray-800 py-1'>Figma</p>
</div>
<div className='text-center shadow-lg p-10 rounded-xl my-10'>
<Image src={design} width={100} height={100} />
<h3 className='text-lg font-medium pt-8 pb-2'>Beautiful designs</h3>
<p className='py-2'>
Creating elegant designs suited for your needs
</p>
<h4 className='py-4 text-teal-600'>Design tools I use</h4>
<p className='text-gray-800 py-1'>photoshop</p>
<p className='text-gray-800 py-1'>Aftereffects</p>
<p className='text-gray-800 py-1'>Blender</p>
<p className='text-gray-800 py-1'>Figma</p>
</div>
<div className='text-center shadow-lg p-10 rounded-xl my-10 '>
<Image src={design} width={100} height={100} />
<h3 className='text-lg font-medium pt-8 pb-2'>Beautiful designs</h3>
<p className='py-2'>
Creating elegant designs suited for your needs
</p>
<h4 className='py-4 text-teal-600'>Design tools I use</h4>
<p className='text-gray-800 py-1'>photoshop</p>
<p className='text-gray-800 py-1'>Aftereffects</p>
<p className='text-gray-800 py-1'>Blender</p>
<p className='text-gray-800 py-1'>Figma</p>
</div>
</div>
</section>

Problem: You are not assigning any styling that would center the image.
Solution: Use Flexbox or Grid to structure elements. (center the image in your case)
Example:
<div className='text-center shadow-lg p-10 rounded-xl my-10 flex flex-col items-center'>
<Image src={design} width={100} height={100} />
<h3 className='text-lg font-medium pt-8 pb-2'>Beautiful designs</h3>
<p className='py-2'>
Creating elegant designs suited for your needs
</p>
<h4 className='py-4 text-teal-600'>Design tools I use</h4>
<p className='text-gray-800 py-1'>photoshop</p>
<p className='text-gray-800 py-1'>Aftereffects</p>
<p className='text-gray-800 py-1'>Blender</p>
<p className='text-gray-800 py-1'>Figma</p>
</div>

Related

Not able to position Div using tailwindCSS

This is my react code:
<div>
<div>
<div className=" grid gap-4 grid-row-4 grid-flow-col">
<div className="row-span-4 h-2/5 w-auto p-2 bg-white">
<p className="m-4 font-bold">
8 task completed out of 10
<br></br>
<h4 className="font-bold">23 December, Sunday</h4>
</p>
<div className="m-4"> Calender </div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Send benefit review by Sunday</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: George Fields
</p>
</div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Invite to office meet-up</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: Rebecca Moore
</p>
</div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Office meet-up</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: Lindsey Stroud
<h2 className="text-blue-1000 font-bold pt-4"> Show More </h2>
</p>
</div>
</div>
<div className="h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Deals </h4>
<AreaChart />
</div>
<div className="h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Tasks</h4>
<ul className="absolute inset-10">
<li className="text-green-600 font-bold">Active</li>
<li className="text-yellow-600 font-bold">Completed</li>
<li className="text-red-600 font-bold">Ended</li>
</ul>
<PieChart />
</div>
</div>
</div>
</div>
I am not able to position these grids, I don't know where to put the class on and also which classes exactly, please bear in mind this is my day 2 of learning tailwind, any help would be appreciated.
I am also attaching the picture of my UI and will point to the area I want to position this grid layout to. Thanks
I tried to use your code as much as possible, here is the result:
The code:
<div className="flex flex-row ">
<div className="flex flex-col w-96">
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
</div>
<div className="grid sm:grid-cols-2 bg-gray-200 w-full">
<p className="m-4 font-bold bg-white">
8 task completed out of 10
<br></br>
<h4 className="font-bold">23 December, Sunday</h4>
</p>
<div className="m-4 h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Deals </h4>
AreaChart
</div>
</div>
</div>

Dynamically changing the height of a div in Tailwind

I have three divs in a grid. the height automatically adjusts to the written content. however, if one div contains too much text, the other two are enlarged incorrectly. I have already tried h-max, h-full and everything else.
Actually, the div in the middle of one of these blocks should be enlarged so that it is always flush at the bottom.
for further information please refer to the picture
<div class="grid grid-cols-6 gap-4">
<div class="bg-green shadow overflow-hidden sm:rounded-lg col-span-2">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-3 font-medium text-gray-100">24 Hours challenge</h3>
</div>
<div class="bg-gray-50 px-4 py-5 text-center">
<a class="text-md font-bold text-gray-500">Ask a stranger if they would like to hear a poem you made. Then improvise a poem if they say yes</a>
</div>
<div class="bg-gray-100 px-4 py-1 text-center">
<a class="text-sm font-medium text-gray-500">06:12:53 left</a>
</div>
</div>
<div class="bg-green shadow overflow-hidden sm:rounded-lg col-span-2">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-3 font-medium text-gray-100">3 Days challenge</h3>
</div>
<div class="bg-gray-50 px-4 py-5 text-center">
<a class="text-md font-bold text-gray-500">Act as if you know a stranger</a>
</div>
<div class="bg-gray-100 px-4 py-1 text-center">
<a class="text-sm font-medium text-gray-500">30:07:00 left</a>
</div>
</div>
<div class="bg-green shadow overflow-hidden sm:rounded-lg col-span-2">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-3 font-medium text-gray-100">Weekly challenge</h3>
</div>
<div class="bg-gray-50 px-4 py-5 text-center">
<a class="text-md font-bold text-gray-500">Sing a song in public</a>
</div>
<div class="bg-gray-100 px-4 py-1 text-center">
<a class="text-sm font-medium text-gray-500">54:06:43 left</a>
</div>
</div>
</div>
flex-grow is the answer thx to Ihar
<div class="bg-gray-50 px-4 py-5 text-center flex-grow">

How to place c2 children to the top and to the bottom of the parent in css?

I need to add 2 children of a parent element one on the top and another on the bottom. something like this.
and this is the code I have.
<div class=" w-full flex justify-betwen bg-white items-center">
<div class="ml-auto">
<img class="object-cover mr-2 md:mr-4 ml-2 md:ml-4 float-left h-40 lg:w-32 w-14 xs:w-16"
src="../img/Bless.png" alt="" />
</div>
<div class="w-full mx-8">
<div class="text-redfull text-ms xs:text-lg md:text-xl lg:text-2xl xl:text-3xl">
Some text here to top as a title.
</div>
<div
class=" text-gray70 flex justify-between items-center text-xs xs:text-base md:text-base lg:text-lg mb-0">
and this is the date to the bottom Uploaded Auguts 4, 2020
</div>
</div>
</div>
Title should stay at the top.
Date to the bottom.
If anyone knows:)
You can add two divs for Title and Date and add vertical margin to them.
I am not sure whether you want with the text or not so I had implemented for both the cases.
Case 1: With text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-3">
<div class="text-ms xs:text-lg text-red-500 md:text-xl lg:text-2xl xl:text-3xl">Some text here to top as a title.</div>
<div class="xs:text-base mb-0 flex items-center justify-between text-xs text-gray-500 md:text-base lg:text-lg">and this is the date to the bottom Uploaded Auguts 4, 2020</div>
</div>
<div class="text-base font-extralight">25 June 2022</div>
</div>
</div>
Case 2: Without Text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-12">
</div>
<div class="text-lg font-extralight">25 June 2022</div>
</div>
</div>
I had use an online image, so you can replace it with your image.
If You want more gap, then simply increase the my-12 to more.

Elements not equal using Flex Box Tailwind CSS

I have section areas that I want to have equal elements. One side is just an image while the other side has content. I'm using Tailwind CSS and feel positive I have the correct classes. The section Divs are declared as Flex while the child elements each have a Flex-basis of 0 and a Flex grow of 1. The content div continues to be a little larger than my image div.
<section class="section-one flex flex-col-reverse md:flex-row-reverse">
<div class="basis-0 grow p-6 text-center md:text-left md:flex md:flex-col md:justify-center md:items-center">
<div>
<h2 class="font-fraunces text-4xl mb-4 md:text-left md:max-w-md">Stand our to the right audience</h2>
<p class="font-barlow text-gray-500 text-lg p-4 mb-6 md:max-w-md md:p-0">Using a collaborative formula of designers, researchers, photographers, videographers and copywriters, we'll build and extend your brand in digital places.</p>
<div class="flex flex-col">
Learn More
<span class="bg-rose-300/75 w-32 mx-auto h-4 rounded-full md:m-0"></span>
</div>
</div>
</div>
<div class="basis-0 grow">
<img src="images/desktop/image-stand-out.jpg" alt="" class="w-full" />
</div>
</section>
If you remove your p-6 class and add in the div below it will work.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<section class="section-one flex flex-col-reverse md:flex-row-reverse">
<div class="basis-0 grow remove-this-p-6 text-center md:text-left md:flex md:flex-col md:justify-center md:items-center">
<div class="p-6"> <!-- add here your padding -->
<h2 class="font-fraunces text-4xl mb-4 md:text-left md:max-w-md">Stand our to the right audience</h2>
<p class="font-barlow text-gray-500 text-lg p-4 mb-6 md:max-w-md md:p-0">Using a collaborative formula of designers, researchers, photographers, videographers and copywriters, we'll build and extend your brand in digital places.</p>
<div class="flex flex-col">
Learn More
<span class="bg-rose-300/75 w-32 mx-auto h-4 rounded-full md:m-0"></span>
</div>
</div>
</div>
<div class="basis-0 grow">
<img src="https://via.placeholder.com/500" alt="" class="w-full" />
</div>
</section>
<section class="section-one flex flex-col-reverse md:flex-row-reverse ">
<div class="basis-0 grow">
<img src="https://via.placeholder.com/500" alt="" class="w-full" />
</div>
<div class="basis-0 grow remove-this-p-6 text-center md:text-left md:flex md:flex-col md:justify-center md:items-center">
<div class="p-6"><!-- add here your pading -->
<h2 class="font-fraunces text-4xl mb-4 md:text-left md:max-w-md">Stand our to the right audience</h2>
<p class="font-barlow text-gray-500 text-lg p-4 mb-6 md:max-w-md md:p-0">Using a collaborative formula of designers, researchers, photographers, videographers and copywriters, we'll build and extend your brand in digital places.</p>
<div class="flex flex-col">
Learn More
<span class="bg-rose-300/75 w-32 mx-auto h-4 rounded-full md:m-0"></span>
</div>
</div>
</div>
</section>
By using grid you can achieve this
Here is the best explanation how to use grid system in tailwindcss
I have made code for you please check here: https://play.tailwindcss.com/wldkQ1txrU

Tailwind scroll to bottom on page load or new line

This is a chat app I am building. What is SUPPOSED to happen with the CSS is the div should always show the latest message at the bottom. When someone types a new message, it should scroll down to the bottom to show the newest message. Right now all it does is post the new message but doesnt scroll and on page reload the oldest message is shown at the top not the newest at the bottom (you gotta scroll to see it.
<div class="h-full pb-2 mb-2 pt-0 mt-0 shadow-md overflow-y-auto">
<div class="flex flex-col-reverse justify-end">
<div class="bg-white">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/2/2021, 12:12:49 PM</p>
</div>
<p class="text-md text-gray-500">this is a test</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-100">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/2/2021, 12:09:34 PM</p>
</div>
<p class="text-md text-gray-500">testing</p>
</div>
</div>
</div>
</div>
<div class="bg-white">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/1/2021, 12:46:38 AM</p>
</div>
<p class="text-md text-gray-500">fhfdgh</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-100">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/1/2021, 12:45:38 AM</p>
</div>
<p class="text-md text-gray-500">https://localhost:8000</p>
</div>
</div>
</div>
</div>
<div class="bg-white">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/1/2021, 12:39:47 AM</p>
</div>
<p class="text-md text-gray-500">How much does it tap into the web server</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-100">
<div>
<div class="flex space-x-3 px-3">
<img class="mt-4 h-8 w-8 rounded-full" src="http://localhost:8000/storage/profile-photos/GGsymBqzbfC6nOWHyFsBEwAdqJtICgo0DcypPlMR.jpg" alt="Ryan Olson">
<div class="flex-1 space-y-1">
<div class="flex items-center justify-between">
<h3 class="pt-2 text-sm font-medium">Ryan Olson</h3>
<p class="text-sm text-gray-500">9/1/2021, 12:39:34 AM</p>
</div>
<p class="text-md text-gray-500">I wonder how this works</p>
</div>
</div>
</div>
</div>
</div>
</div>
I am just not sure what I am missing.
inside <div class="flex flex-col-reverse justify-end"> I had to also put h-full

Resources