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
Related
I'm using Tailwind CSS and React to build an app, and in one of view I have a grid of cards. Currently it looks something like this:
As you can see, the cards squeeze in as I make the window smaller. I want to ensure that the cards size (width and height) always stays the same, and it just moves to the next row if the amount of cards don't fit on one row as the window gets smaller.
Something like (made in MS paint):
Where the size of the cards stay fixed (same aspect ratio) even though the screen is getting smaller.
Here's how my code looks currently:
Grid:
<div>
<ul className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-4 md:grid-cols-6 md:gap-4 lg:grid-cols-8 lg:gap-4">
{props.trips.map((trip: TTrip) => (
<TripCard trip={trip} href={currentPath + trip.id} />
))}
</ul>
</div>
Card:
<li
key={props.trip.id}
className="card card-compact shadow-xl col-span-1 w-128 h-fit bg-gray-100 hover:bg-base-200"
>
<div className="relative w-128 h-32">
<Image src="https://placeimg.com/500/225/arch" layout="fill" objectFit="cover" />
</div>
<div className="card-body">
<h2 className="card-title">{props.trip.name}</h2>
<h2>Time - Time</h2>
</div>
</li>
Any idea how to set this up using tailwind-css?
I know you wanted to set this up using Grid, but unfortunately, it is not the right tool for this job. Flexbox would be best suited for your needs.
Here is a tailwind playground that shows your desired output. The playground I linked doesn't use NextJS, as it does in your example. So, I have modified a few things such as images, as they are non-NextJS specific.
I have modified the styling a bit, in a way I felt is more efficient. Namely, I have moved the width setting from the image, to the container div. You can further modify this setup, as per your requirement.
In your setup, the code would translate roughly like this.
// Grid
<div>
<ul className="flex flex-row gap-4 flex-wrap">
{props.trips.map((trip: TTrip) => (
<TripCard trip={trip} href={currentPath + trip.id} />
))}
</ul>
</div>
// Card
<li
key={props.trip.id}
className="card card-compact shadow-xl col-span-1 w-32 md:w-72 lg:w-96 h-fit bg-gray-100 hover:bg-base-200"
>
<div className="relative h-32">
<Image src="https://placeimg.com/500/225/arch" layout="fill" objectFit="cover" />
</div>
<div className="card-body">
<h2 className="card-title">{props.trip.name}</h2>
<h2>Time - Time</h2>
</div>
</li>
Here's how it would look:
Largest with wrapping
Medium without wrapping
Small without wrapping
Small with wrapping
The exact breakpoints where the size and wrapping changes, depends on how you decide to implement it. If you are unhappy with the above points, you can simply modify the lg, md prefixes, as per your needs.
The simplest way of getting this done is via flex and flex-wrap and setting fixed desired height and width for the cards
Code Structure:
<div class="flex flex-wrap"> 👈 Use flex flex-wrap
<card>
<card>
<card>
</div>
Tailwind-play
Code:
<div class="flex flex-wrap">
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
<div class="w-56 rounded-lg bg-gray-200 shadow-lg">
<div class="h-40"><img src="https://placeimg.com/500/225/hous" class="h-full" /></div>
<div class="pl-2 text-4xl">Title</div>
<div class="pl-2 text-2xl">Subtitle</div>
</div>
</div>
Output in different screens:
<html>
<body>
<div class="group card my-14 mx-3 w-80 h-100 bg-gray-800 rounded-xl text-white p-5 cursor-pointer">
<div class=" flex justify-between items-center text-2xl ">
<i class='bx bx-heart'></i>
<i class='bx bx-cart-alt'></i>
</div>
<div class="w-11/12 ml-2.5 group-hover:text-white group-hover:-rotate-20">
<img class="object-cover w-full h-full" src="./Images/Jordan.png" id="bannerImage" alt="">
</div>
<div class="text-center uppercase text-xl text-green-600">
Jordan 1 <br>
$299
</div>
</div>
</body>
</html>
Explain why Styling based on parent state doesn't work.
...................................
Tailwind doesn't have -rotate-20 utility class. Change it to one of known or use arbitrary value like group-hover:-rotate-[20deg]
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.
So this is the code I am working with:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.1.2/tailwind.min.css" />
<div class=" h-48 p-3 bg-gray-700">
<div class="h-full w-48 bg-gray-700 border border-gray-300">
<div class="h-6 bg-gray-400 opacity-50 w-full">
Username
</div>
<img class="w-full object-contain" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330" />
</div>
</div>
I am having issues getting the image to constrain to the parent div. What I want to accomplish is to have the user image constrain inside the parent div and not overflow outside the border. The image attached is what it looks like now. I have no idea what I am doing wrong or missing.
make it a flexbox container
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div class=" h-48 p-3 bg-gray-700">
<div class="h-full w-48 bg-gray-700 border border-gray-300 flex flex-col">
<div class="h-6 bg-gray-400 opacity-50 w-full">
Username
</div>
<img class="w-full object-contain min-h-0" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330" />
</div>
</div>
OR CSS grid:
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div class=" h-48 p-3 bg-gray-700">
<div class="h-full w-48 bg-gray-700 border border-gray-300 grid">
<div class="h-6 bg-gray-400 opacity-50 w-full">
Username
</div>
<img class="w-full object-contain min-h-0 h-full" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330" />
</div>
</div>
Use flex flex-col on parent container and add min-h-0 to image.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.1.2/tailwind.min.css" />
<div class=" h-48 p-3 bg-gray-700">
<div class="h-full w-48 bg-gray-700 border border-gray-300 flex flex-col">
<div class="h-6 bg-gray-400 opacity-50 w-full">
Username
</div>
<img class="w-full object-contain min-h-0" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330" />
</div>
</div>
I need to programm the following design
I want to give the big image in the middle (dark red) the rematining space of my flexcontainer, where the yellow stuff is margin/paddings. The problem i have here is, that my image always overlapps the flex container and also the images in the bottom and the svgs. I dont want to give the image a fixed height nor some percentage values because i want to keep it responsive and dynamicaly. Here is my code:
<div
class="flex flex-col flex-1 fixed bg-black w-auto inset-x-11 inset-y-10 z-1003">
</svg>
<div class="fixed flex flex-1 flex-col inset-x-20 inset-y-20">
<div class="flex h-3/4 justify-center items-center">
<svg
</svg>
<img
class="mx-6 w-5/6 h-full bg-gray-light border-2 rounded-md"
My Big Image
/>
<svg
</svg>
</div>
<div class="flex w-full flex-row flex-1 items-end justify-center mt-6">
<div v-for="img in 3" class="mx-6 bg-black-normal rounded-lg">
<img
the orange images
/>
</div>
</div>
</div>
The best solution here would be for me to remove every heights and only work with flex flex-1 flex-shrink and so on but its not working properly as expected.
You can do this in many ways. Flexboxes are good approach, but for for thumbnails images I would use grid to make them even (but sure flexboxes can by used as well).
It does not matter if you use SVG or not for buttons. But if you have any problem with them - please provide real reproduction example (https://play.tailwindcss.com/ can be usefully).
Demo: https://play.tailwindcss.com/RsXsrdSYG3
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<div class="min-h-screen bg-gray-50 p-8 flex flex-col">
<div class="flex items-center">
<button class="flex-none w-16 h-16 bg-gray-500">PREV</button>
<div class="px-6">
<img src="https://via.placeholder.com/1920x1080" />
</div>
<button class="flex-none w-16 h-16 bg-gray-500">NEXT</button>
</div>
<div class="mt-6 grid grid-cols-3 gap-6">
<img src="https://via.placeholder.com/1920x1080" />
<img src="https://via.placeholder.com/1920x1080" />
<img src="https://via.placeholder.com/1920x1080" />
</div>
</div>
Or if you want to fill screen height (but empty space will be visible over big image to keep responsive ratio).
Demo: https://play.tailwindcss.com/hTYuGjPHHk
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<div class="h-screen bg-gray-50 p-8 flex flex-col">
<div class="flex items-center flex-1">
<button class="flex-none w-16 h-16 bg-gray-500">PREV</button>
<div class="px-6 h-full flex items-center">
<img src="https://via.placeholder.com/1920x1080" />
</div>
<button class="flex-none w-16 h-16 bg-gray-500">NEXT</button>
</div>
<div class="mt-6 grid grid-cols-3 gap-6">
<img src="https://via.placeholder.com/1920x1080" />
<img src="https://via.placeholder.com/1920x1080" />
<img src="https://via.placeholder.com/1920x1080" />
</div>
</div>