Aligning Content in Tailwind CSS - css

I need to align the image and the Orange and fruit on the center.
How will I do it the proper and correct way. It needs to align together with others.
Check my playground here CLICK HERE
expected output
<div class="bg-black overflow-auto h-screen pb-24 px-4 md:px-6">
<div class="flex flex-col w-full p-12">
<div class="flex flex-col w-full text-center items-center">
<div class="btc">
<button class="btn btn-back">Back</button>
<div class="flex gap-4">
<img src="https://picsum.photos/200/300" class="w-12 h-12" />
<div class="text-left text-white">
<p class="font-bold">Orange</p>
<p class="text-grey">fruit</p>
</div>
</div>
</div>
<h1 class="text-4xl text-white mb-5">
<span class="text-sm font-bold">Food</span>
</h1>
<div class="flex flex-row mt-8 gap-4">
<button class="btn btn-primary">Send Food</button>
<button class="btn btn-yellow">Receive Food</button>
</div>
<div class="flex flex-row mt-8 mb-16">
<button class="btn btn-change flex justify-center items-center">
<span class="w-5 h-5 bg-blue-button-bg rounded-full mr-2"></span>
<span>Change Food</span>
</button>
</div>
</div>
</div>
</div>

.btc {
#apply w-full mb-16;
display: grid;
grid-gap: 1rem;
grid-template-columns: auto;
justify-content: center;
position: relative;
}
.btn {
#apply text-white text-sm bg-transparent font-normal rounded-full border-2 h-10 w-52;
}
.btn-back {
#apply border-green-500 w-24;
}
.btn-primary {
#apply border-red-700;
}
.btn-yellow {
#apply border-yellow-300;
}
.btn-change {
#apply bg-blue-300 border-0 font-bold;
}
.btn-class {
position: absolute;
left: 0;
top: 0;
}
<div class="bg-black overflow-auto h-screen pb-24 px-4 md:px-6">
<div class="flex flex-col w-full p-12">
<div class="flex flex-col w-full text-center items-center">
<div class="btc">
<button class="btn btn-back btn-class">Back</button>
<div class="flex gap-4 new-div-class">
<img src="https://picsum.photos/200/300" class="w-12 h-12" />
<div class="text-left text-white">
<p class="font-bold">Orange</p>
<p class="text-grey">fruit</p>
</div>
</div>
</div>
<h1 class="text-4xl text-white mb-5">
<span class="text-sm font-bold">Food</span>
</h1>
<div class="flex flex-row mt-8 gap-4">
<button class="btn btn-primary">Send Food</button>
<button class="btn btn-yellow">Receive Food</button>
</div>
<div class="flex flex-row mt-8 mb-16">
<button class="btn btn-change flex justify-center items-center">
<span class="w-5 h-5 bg-blue-button-bg rounded-full mr-2"></span>
<span>Change Food</span>
</button>
</div>
</div>
</div>
</div>
I have edited your play. Here is the new link https://play.tailwindcss.com/qrDlxDYWW3

Related

Equal-width columns in CSS with flexbox and Tailwind

I want to have a flexbox layout where three columns have the same width.
I have to use Tailwind in this case, but it doesn't change the CSS theory... which, as far as I know, says I need to give the three columns the same basis, and then let them grow freely (all of them will grow the same proportion because they have the same basis).
But it's not working. One of the column gets bigger and I don't know why.
Note: I added a border just to make it visually clear, but I don't need that.
.just-a-border {
border: 2px dotted purple;
}
<link href="https://unpkg.com/tailwindcss#2.2.19/dist/tailwind.min.css" rel="stylesheet" />
<div class="grow flex flex-nowrap items-center gap-5 justify-center py-12 flex-row">
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">I want to have more words</div>
<div class="font-medium">6 hours</div>
</div>
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">Yes</div>
<div class="font-medium">1 hour</div>
</div>
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">No</div>
<div class="font-medium">3 hours</div>
</div>
</div>
Any idea to make it work?
You used the classes from Tailwind CSS v3. So, if you upgrade your Tailwind CSS version to v3, your codes will be just working good.
If you want to keep the current version which is v2, you just need to update a few of class names in your current codes like below. basis-1 to flex-1, grow to flex-grow
<style>
.just-a-border {
border: 2px dotted purple;
}
</style>
<div class="flex flex-row flex-nowrap items-center gap-5 justify-center py-12">
<div class="just-a-border h-full p-6 text-center flex-1 flex-grow">
<div class="mb-2 text-sm font-medium uppercase">I want to have more words</div>
<div class="font-medium">6 hours</div>
</div>
<div class="just-a-border h-full p-6 text-center flex-1 flex-grow">
<div class="mb-2 text-sm font-medium uppercase">Yes</div>
<div class="font-medium">1 hour</div>
</div>
<div class="just-a-border h-full p-6 text-center flex-1 flex-grow">
<div class="mb-2 text-sm font-medium uppercase">No</div>
<div class="font-medium">3 hours</div>
</div>
</div>
It appears you are using Tailwind classes from version 3 while you are using version 2.2.19.
I added the following classes to your css and it now gives even columns.
.grow {
flex-grow: 1;
}
.basis-1 {
flex-basis: 0.25rem;
}
Also see the Play demo which uses your code, unchanged, and works as you would have expected.
https://play.tailwindcss.com/VjbHZcTiVH
.just-a-border {
border: 2px dotted purple;
}
.grow {
flex-grow: 1;
}
.basis-1 {
flex-basis: 0.25rem;
}
<link href="https://unpkg.com/tailwindcss#2.2.19/dist/tailwind.min.css" rel="stylesheet" />
<div class="grow flex flex-nowrap items-center gap-5 justify-center py-12 flex-row">
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">I want to have more words</div>
<div class="font-medium">6 hours</div>
</div>
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">Yes</div>
<div class="font-medium">1 hour</div>
</div>
<div class="just-a-border h-full p-6 text-center basis-1 grow">
<div class="mb-2 text-sm font-medium uppercase">No</div>
<div class="font-medium">3 hours</div>
</div>
</div>
You can use grid for that, instead of flex. Defining the number of columns with grid-cols-3 will create three columns of equal width and height.
See playground example and tailwind docs.
<div class="grid w-full grid-cols-3 flex-row justify-center gap-5 py-12">
<div class="rounded-lg border border-slate-300 p-6 text-center">
<div class="mb-2 text-sm font-medium uppercase">I want to have more words</div>
<div class="font-medium">6 hours</div>
</div>
<div class="rounded-lg border border-slate-300 p-6 text-center">
<div class="mb-2 text-sm font-medium uppercase">Yes</div>
<div class="font-medium">1 hour</div>
</div>
<div class="rounded-lg border border-slate-300 p-6 text-center">
<div class="mb-2 text-sm font-medium uppercase">No</div>
<div class="font-medium">3 hours</div>
</div>
</div>

React to print fixed footer overlapping contents

I am using a react-to-print library to print some reports that are dynamic. The problem is I need a fixed footer on every page while printing and I have a fixed footer which overlaps the content before going to new page . I know how position:fixed works and would have solved if reports weren't dynamic. What can be the possible fix here?
My PrintingComponenet is
<div className="page-footer">
<hr />
<p className="pt-1">For screening purposes only. Not for use in diagnostic procedures</p>
<div className="flex w-full items-center justify-between">
<div>
Printed By ( <span className="text-primary-700">{!isServer && window.location.hostname}</span>{" "}
) on {moment(new Date()).format("MMM Do YYYY, h:mm:ss A")}
</div>
<span>{member.member_code}</span>
</div>
</div>
<div className="w-full">
{Object.keys(test).map((el, index) => (
<div key={el}>
<div style={{ height: "100px" }} />
<div className=" bg-gray-700 mt-4 px-3 capitalize py-4 text-xl text-white font-medium space-y-2 whitespace-nowrap">
{el} Test Report
</div>
{el === "Body Mass Index" ? (
<>
<div className="flex mt-3 border-b pb-3">
<div className="text-gray-600 flex-1 text-2xl">Test Date</div>
<div className="text-gray-600 flex-1 text-2xl">Temperature</div>
<div className="text-gray-600 flex-1 text-2xl">Test Result</div>
</div>
{test[el].map((el: any, index: number) => (
<div key={el.test_date} className="flex mt-4 border-b pb-2 last:border-0 ">
<div className=" flex-1 text-xl">
<span className="block">{moment(utcDateToLocal(el.test_date)).format("MM/DD/YYYY")}</span>
<span className="block">{moment(utcDateToLocal(el.test_date)).format("h:mm A")}</span>
</div>
<div className=" flex-1 text-xl">
{el.temperature} {el.temperature && <>° F</>}{" "}
</div>
<div className=" flex-1 text-xl ">Test</div>
</div>
))}
</>
) : (
<>
<div className="flex mt-3 border-b pb-3">
<div className="text-gray-600 flex-1 text-2xl">Test Date</div>
<div className="text-gray-600 flex-1 text-2xl ">Test Result</div>
</div>
{test[el].map((el: any, index: number) => (
<div key={el.test_date} className="flex mt-4 border-b pb-2 last:border-0 ">
<div className=" flex-1 text-xl">
<span className="block">{moment(utcDateToLocal(el.test_date)).format("MM/DD/YYYY")}</span>
<span className="block">{moment(utcDateToLocal(el.test_date)).format("h:mm A")}</span>
</div>
<div className=" flex-1 text-xl ">
<div>Test Result</div>
<div>Test Result</div>
<div>Test Result</div>
<div>Test Result</div>
<div>Test Result</div>
</div>
</div>
))}
</>
)}
</div>
CSS for footer is
.page-footer {
height: 30px;
position: fixed;
bottom: 0;
width: 100%;
}
#media print {
.page-footer {
page-break-after: always;
}
}

Is there a way to put these bars behind the circles?

I couldn't understand how to put these bars behind the circles:
REPL: https://play.tailwindcss.com/peSieAptHf
I'm trying with z-index but it doesn't work!
Is there an alternative way?
<div class="flex w-full p-20">
<div class="w-full">
<div class="flex mx-auto w-8 h-8 bg-gray-300 rounded-full"></div>
</div>
<div class="w-full">
<div class="relative">
<div class="flex mx-auto w-8 h-8 bg-blue-300 rounded-full"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-green-500"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-blue-500 rounded-full"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-gray-700"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-green-500 rounded-full"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-red-500"></div>
</div>
</div>
</div>
</div>
z-index can be triggered on the rounds if you reset the static position to relative via classes : relative z-10 .
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<div class="flex w-full p-20">
<div class="w-full">
<div class="flex mx-auto w-8 h-8 bg-gray-300 rounded-full relative z-10"></div>
</div>
<div class="w-full">
<div class="relative">
<div class="flex mx-auto w-8 h-8 bg-blue-300 rounded-full relative z-10"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-green-500"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-blue-500 rounded-full relative z-10"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4 ">
<div class="h-0.5 w-full bg-gray-700"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-green-500 rounded-full relative z-10"></div>
<div class="absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-red-500"></div>
</div>
</div>
</div>
</div>
You need to set negative z-index to the bars.
To set negative z-index, check the docs at https://tailwindcss.com/docs/z-index#negative-values
After adding the negative z-index setup, your code should look like this:
<div class="flex w-full p-20">
<div class="w-full">
<div class="flex mx-auto w-8 h-8 bg-gray-300 rounded-full"></div>
</div>
<div class="w-full">
<div class="relative">
<div class="flex mx-auto w-8 h-8 bg-blue-300 rounded-full"></div>
<div class="-z-10 absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-green-500"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-blue-500 rounded-full"></div>
<div class="-z-10 absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-gray-700"></div>
</div>
</div>
</div>
<div class="w-full">
<div class="relative">
<div class="mx-auto w-8 h-8 bg-green-500 rounded-full"></div>
<div class="-z-10 absolute inset-0 flex items-center -translate-x-2/4">
<div class="h-0.5 w-full bg-red-500"></div>
</div>
</div>
</div>
</div>
I tried doing it with css and it worked out:
.container {
width: 100px;
height: 100px;
background: red;
z-index: 9999;
}
.bar {
background: blue;
width: 200px;
height: 10px;
position: fixed;
margin-top: 50px;
margin-left: 80px;
z-index: -1;
}
Html:
<div class="bar"></div>
<div class="container"></div>

Auto-stretch tailwind body to adapt to other div

I'm using Tailwind CSS in VueJS and I have a little issue with my DIVs. I'm not used to CSS frameworks and I never encountered this problem before.
Problem : https://i.ibb.co/XWbdsxT/screenshot.png
As you can see on this screenshot, the red div goes beyond the bottom of the page (which is normal). I would like the dark-gray one and the light-gray one to strech and follow the red to the very bottom.
I tried :
Add h-full or/and h-screen classes to the gray divs
Add h-full or and h-screen classes to the body and/or html
Add these classes to the main parent div (the one where the grays are wrapped)
It doesn't seem to have any effect. Am I doing this wrong ? Here is the code :
<template>
<div class="hello">
<div class="flex flex-row">
<div class="w-1/5 h-screen bg-darkgray"></div>
<div class="w-4/5 h-screen bg-gray-200">
<div class="w-full h-16">
<div>
<div class="bg-white flex items-center shadow-xl">
<input class="w-full py-4 px-6 text-gray-700 leading-tight focus:outline-none" id="search" type="text" placeholder="Search an article">
<div class="p-4 flex flex-column">
<div class="border-r-2 w-16">
<button class="text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/search_icon.png"/>
</button>
</div>
<div class="flex flex-column">
<button class="ml-3 text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/notifications.png"/>
</button>
<button class="ml-3 text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/user.png"/>
</button>
</div>
</div>
</div>
</div>
</div>
<div>
<div class="flex flex-row w-11/12 h-16 mt-20 m-auto justify-between">
<p class="text-3xl font-bold">Dashboard</p>
<button class="bg-orange hover:bg-darkgray text-white font-bold h-12 px-4 rounded-xl justify-end" type="button">
<span class="mr-2">+</span> Create an article
</button>
</div>
<div class="flex flex-row w-11/12 h-16 mt-4 m-auto bg-white rounded-t-2xl justify-between">
<div class="ml-6 mt-5">
<a class="text-orange font-bold">HIGHLIGHTS ARTICLES</a>
</div>
<div class="flex justify-end ml-6 mt-5 mr-6 space-x-4">
<div id="1" class="selected cursor-pointer"><a class="item-selected font-bold">Recently updated</a></div>
<div id="2" class="cursor-pointer"><a class="item font-bold">Recently seen</a></div>
<div id="3" class="cursor-pointer"><a class="item font-bold">Created by me</a></div>
</div>
</div>
<div class="flex w-11/12 h-5xl mt-0.5 bg-red-500 m-auto rounded-b-2xl"></div>
</div>
</div>
</div>
</div>
</template>
Please don't pay attention to the fact that this is not responsive. It is not supposed to be.
Try this,
your Dashboard content area needed overflow:hidden. check this doc
<div class="flex flex-row w-full h-screen">
<div class="w-1/5 max-h-full bg-gray-800 text-white p-6">Sidebar</div>
<div class="flex flex-col w-full max-h-full bg-gray-200">
<div class="flex flex-row w-full bg-white items-center shadow-xl">
<input class="w-full py-4 px-6 text-gray-700 leading-tight focus:outline-none" id="search" type="text" placeholder="Search an article" />
<div class="flex p-4 flex-column">
<div class="border-r-2 w-16">
<button class="text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/search_icon.png" />
</button>
</div>
<div class="flex flex-column">
<button class="ml-3 text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/notifications.png" />
</button>
<button class="ml-3 text-darkgray rounded-full p-2 hover:bg-gray-100 focus:outline-none w-12 h-12 flex items-center justify-center">
<img src="../assets/user.png" />
</button>
</div>
</div>
</div>
<div class="flex flex-col max-w-full m-6 h-full rounded-b-2xl overflow-hidden">
<div class="flex flex-row w-full my-6 m-auto justify-between">
<p class="text-3xl font-bold">Dashboard</p>
<button class="bg-yellow-500 hover:bg-darkgray text-white font-bold h-12 px-4 rounded-xl justify-end" type="button"><span class="mr-2">+</span> Create an article</button>
</div>
<div class="flex flex-row w-full bg-white rounded-t-2xl justify-between px-6 py-6 h-16">
<a class="text-orange font-bold">HIGHLIGHTS ARTICLES</a>
<div class="flex justify-end space-x-4">
<div id="1" class="selected cursor-pointer"><a class="item-selected font-bold">Recently updated</a></div>
<div id="2" class="cursor-pointer"><a class="item font-bold">Recently seen</a></div>
<div id="3" class="cursor-pointer"><a class="item font-bold">Created by me</a></div>
</div>
</div>
<div class="flex w-full mt-0.5 bg-red-500 rounded-b-2xl max-h-full p-6">Test Doc</div>
</div>
</div>
</div>
Check on Tailwind Play

Tailwind: can't get the elements to fill the width

Fiddle: https://play.tailwindcss.com/epT13JJxnk
It looks like this:
I need it to look like this:
How do I achieve it?
Fiddle code:
<div id="app" class=" border border-white
h-screen font-sans tracking-normal mt-10">
<nav data-v-5e628c52="" class="pt-2 md:pt-1
pb-1 px-1 mt-0 h-auto
fixed w-full z-20 top-0">
<div data-v-5e628c52="" class="flex flex-wrap items-center justify-between
m-3 p-2 pl-6 ">
<div data-v-5e628c52="" class="flex flex-wrap items-center justify-start"><a data-v-5e628c52="" href="#" class="header-item title-text light-text text-xl router-link-exact-active router-link-active" aria-current="page">Link1 </a><a data-v-5e628c52="" href="#" class="header-item pl-10">Link2 </a><a data-v-5e628c52="" href="#" class="header-item pl-10 router-link-exact-active router-link-active" aria-current="page">Link3 </a><a data-v-5e628c52="" href="#" class="header-item pl-10 router-link-exact-active router-link-active" aria-current="page">Link4 </a><a data-v-5e628c52="" href="#" class="header-item pl-10">Link5 </a></div>
<div data-v-5e628c52="" class="flex flex-wrap items-center justify-end ">
<!----><!---->
<div data-v-5e628c52="">
<div data-v-24cf0f3c="" data-v-5e628c52="">
<div data-v-24cf0f3c="" class=" ">
<div data-v-24cf0f3c="" class="dropdown inline-block relative">
<button data-v-24cf0f3c=""><img data-v-24cf0f3c="" src="/img/some-image.png" class=" rounded-full border
border-gray-100 shadow-sm w-12
"></button>
<ul data-v-24cf0f3c="" class="right-0 dropdown-menu absolute hidden text-gray-800 pt-1">
<li data-v-24cf0f3c="" class=""><a data-v-24cf0f3c="" href="/user/test" class="rounded-t
py-2 px-4 block whitespace-no-wrap">Profile</a></li>
<li data-v-24cf0f3c=""><a data-v-24cf0f3c="" href="#" class="
py-2 px-4 block whitespace-no-wrap">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
<div id="main-content" class=" border border-red flex justify-center
flex-col items-center space-between min-h-screen w-full
mt-12 md:mt-12 pb-24 md:pb-5 p-5">
<div>
<div data-v-e33ade5c="" class=" ">
<div data-v-87eacdd8="" data-v-e33ade5c="" class="w-full shadow-xl rounded-sm
p-10 pb-5 m-10 pt-5 article flex flex-col
content-between flex-1 flex-grow " name="46">
<div data-v-87eacdd8="" class="flex flex-row justify-between">
<div data-v-87eacdd8="" class="cursor-pointer title-text article-title">last article</div>
<div data-v-87eacdd8="" class="article-date">4/22/2021</div>
</div>
<div data-v-87eacdd8="" class="pt-5 article-text ">last article</div>
<div data-v-87eacdd8="" class="flex flex-wrap mt-5 mb-2 ">
<div data-v-09e62cea="" data-v-87eacdd8="" tag="Hashtag" name="last" class="inline-flex mr-2 ">
<div data-v-09e62cea="" class="tag rounded-full p-2 "> last</div>
</div>
<div data-v-09e62cea="" data-v-87eacdd8="" tag="Hashtag" name="yes" class="inline-flex mr-2 ">
<div data-v-09e62cea="" class="tag rounded-full p-2 "> yes</div>
</div>
</div>
<div data-v-87eacdd8="" class=" font-bold light-text "> Comments: 0 </div>
<!---->
</div>
</div>
</div>
<div id="up-button" class=" sticky text-xl cursor-pointer
mt-auto ml-auto
bottom-5 right-5 rounded-lg p-5 "> UP </div>
</div>
<footer></footer>
</div>
EIDT:
I tried to add an extra wrapper with w-full as the answer suggests, but now the child div (gray) is too huge and goes outside the outer div id="app" (yellow). Also the UP button breaks: it's no longer small, but is very wide:
https://play.tailwindcss.com/8XBRUdNaX2
Change items-center to items-stretch on #main-content.
Remove w-full from the item div[name=46]
See example: https://play.tailwindcss.com/TZQHATbdll
Just need to add class to a div. Also, adjust some paddings and you are good to go.
<div id="main-content">
<div class="w-full">
The wrapper div needs a w-full class, too (as #Digvijay already pointed out). Then, some classes of the name="46" element must be removed, especially w-full, which applies a 100% width that is added to the padding defined on the element, adding up to more than 100%.
See the updated example: https://play.tailwindcss.com/1vDd7ToPLt
Remove items-center class from <div id="main-content">
Remove m-10 from <div class="" name="46">
Link

Resources