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>
Related
I am struggeling while trying to center my content vertical and horizontal within a nested div with tailwindcss.
<div class="flex flex-col items-center min-h-screen">
<header class="flex-none text-center w-full">
<p>Header</p>
</header>
<div class="grow w-full">
<div id="home" class="flex justify-center item-center min-h-max">
<main>
<p>Shall be vertical and horizontal center.</p>
</main>
</div>
</div>
<footer class="flex-none text-center m-2 w-full">
<hr class="mx-auto mb-2 sm:w-56 w-36 h-0.5 bg-gray-100 rounded border-0 shadow-2xl" />
<div class="flex sm:flex-row flex-col sm:gap-4 gap-1 justify-center text-sm font-light">
<p>Footer<p>
</div>
</footer>
</div>
The code is also wrapped up here: https://play.tailwindcss.com/5B2w0RGQzm?size=540x1014
I already tried different height and min-height classes, but I am still failing...
https://tailwindcss.com/docs/height
https://tailwindcss.com/docs/min-height
What is the right approach to align everything centered?
try to dispatch your class otherwise and allow yourself to set flex (#child) into flex (from parent) , so it respects your idea and uses flex grid properties through your DOM levels.
Possible example below if i understood your issue:
<script src="https://cdn.tailwindcss.com"></script>
<div class="flex flex-col items-center min-h-screen" style="">
<header class="flex-none text-center w-full">
<p>Header</p>
</header>
<div class="flex flex-column grow w-full justify-center items-center">
<div id="home">
<main>
<p>Shall be vertical and horizontal center.</p>
</main>
</div>
</div>
<footer class="flex-none text-center m-2 w-full">
<hr class="mx-auto mb-2 sm:w-56 w-36 h-0.5 bg-gray-100 rounded border-0 shadow-2xl" />
<div class="flex sm:flex-row flex-col sm:gap-4 gap-1 justify-center text-sm font-light">
<p>Footer at bottom <p>
</div>
</footer>
</div>
other possible example:
<script src="https://cdn.tailwindcss.com"></script>
<div class="flex flex-col items-center min-h-screen" style="">
<header class="flex-none text-center w-full">
<p>Header</p>
</header>
<div class="flex grow ">
<div id="home" class="flex grow ">
<main class="flex flex-column grow w-full justify-center items-center">
<p>Shall be vertical and horizontal center.</p>
</main>
</div>
</div>
<footer class="flex-none text-center m-2 w-full">
<hr class="mx-auto mb-2 sm:w-56 w-36 h-0.5 bg-gray-100 rounded border-0 shadow-2xl" />
<div class="flex sm:flex-row flex-col sm:gap-4 gap-1 justify-center text-sm font-light">
<p>Footer at bottom
<p>
</div>
</footer>
</div>
I am trying to center the rounded full image between the main cover photo and the left column. For some reason I cannot get it to move from the top left corner and I cannot see what I am doing wrong. I am using Tailwind CSS.
<Head :title="profile.name" />
<div class="relative w-full max-h-screen bg-gray-900 flex justify-start items-center rounded-lg">
<div class="relative flex w-full h-48 bg-gray-700">
<img :src="profile.cover_photo_path" class="cover-bg w-full "/>
<div class="absolute inset-0 bottom-0 left-0">
<img :src="profile.profile_photo_path" class="w-48 h-48 rounded-full border-2 border-red-600"/>
</div>
</div>
</div>
<div class="flex flex-row">
<!-- Left Column -->
<div class="bg-gray-900 w-1/3 h-96 z-0">
</div>
<!-- Right Column -->
<div class="bg-gray-900 w-2/3 h-48 z-0">
<div class="flex flex-row justify-between px-2 items-center h-12 border-b border-red-700">
<div class="text-white text-center font-normal"> Feed </div>
<div class="text-white text-center font-normal"> About </div>
<div class="text-white text-center font-normal"> Photos </div>
<div class="text-white text-center font-normal"> Videos </div>
<div class="text-white text-center font-normal"> Events </div>
<div class="text-white text-center font-normal"> Groups </div>
<div class="text-white text-center font-normal"> Pages </div>
<div class="text-white text-center font-normal"> Followers </div>
<div class="text-white text-center font-normal"> Following </div>
</div>
</div>
</div>
</template>
As far as I understood , you want the circle rounded image in the middle of cover and left sidebar vertically and over them.
So I had created this ,please verify if you want. Else I would rather suggest you to attach a screenshot of what you want .
<script src="https://cdn.tailwindcss.com"></script>
<div class="relative flex max-h-screen w-full items-center justify-start rounded-lg bg-gray-900">
<div class="relative flex h-48 w-full bg-gray-700">
<img src="http://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg" class="cover-bg w-full" />
<div class="absolute inset-0 top-1/2 left-10 z-10">
<img src="http://codeskulptor-demos.commondatastorage.googleapis.com/pang/IHXoEES.png" class="h-48 w-48 rounded-full border-2 border-red-600" />
</div>
</div>
</div>
<div class="flex flex-row">
<!-- Left Column -->
<div class="z-0 h-96 w-1/3 bg-gray-900"></div>
<!-- Right Column -->
<div class="z-0 h-48 w-2/3 bg-gray-800">
<div class="flex h-12 flex-row items-center justify-between border-b border-red-700 px-2">
<div class="text-center font-normal text-white">Feed</div>
<div class="text-center font-normal text-white">About</div>
<div class="text-center font-normal text-white">Photos</div>
<div class="text-center font-normal text-white">Videos</div>
<div class="text-center font-normal text-white">Events</div>
<div class="text-center font-normal text-white">Groups</div>
<div class="text-center font-normal text-white">Pages</div>
<div class="text-center font-normal text-white">Followers</div>
<div class="text-center font-normal text-white">Following</div>
</div>
</div>
</div>
How can I make the second column use the minimum amount of space needed?
https://play.tailwindcss.com/tYdbqCSfoh?size=540x720
I have this:
But I want this instead:
<div class="min-h-screen bg-gray-50 py-6 flex flex-col justify-center relative overflow-hidden sm:py-12">
<div class="relative bg-gray-600">
<div class="max-w-full m-2">
<div class="grid gap-2 grid-flow-col bg-blue-300">
<div class="bg-green-200">sdf</div>
<div class="bg-red-200">sdf</div>
</div>
</div>
</div>
</div>
Just add grid-cols-1
<script src="https://cdn.tailwindcss.com"></script>
<div class="min-h-screen bg-gray-50 py-6 flex flex-col justify-center relative overflow-hidden sm:py-12">
<div class="relative bg-gray-600">
<div class="max-w-full m-2">
<div class="grid grid-cols-1 gap-2 grid-flow-col bg-blue-300">
<div class="bg-green-200">sdf</div>
<div class="bg-red-200">sdf</div>
</div>
</div>
</div>
</div>
I'm having trouble getting the right, "Scroll independently", div, to scroll independently of its sibling div to its left. I would like to be able to do this without changing anything outside of the <!-- CONTENT START --> <!-- CONTENT END --> comments. It seems to be close, but I'm stuck. The "Scroll" and "Scroll independently" div's always scroll together. I'm running this in https://play.tailwindcss.com/
Any help would be greatly appreciated.
<div class="flex bg-gray-100 justify-center">
<div class="flex flex-col w-full max-w-5xl pb-7">
<nav class="sticky top-0 flex items-center justify-between bg-gray-700 text-white h-16 z-40 p-2">
<div class="flex w-1/3">
{Left}
</div>
<div class="flex justify-center w-1/3">
{Middle}
</div>
<div class="flex justify-end items-center w-1/3 gap-2">
{Right}
</div>
</nav>
<!-- CONTENT START -->
<div class="flex">
<div class="w-2/3">
<div class="sticky top-16 w-full h-20 mb-2 bg-green-500">
Don't scroll
</div>
<div class="w-full h-96 mb-2 bg-red-500">
Scroll
</div>
</div>
<div class="w-1/3 mb-2 h-[1000px] bg-pink-400">
Scroll independently
</div>
</div>
<!-- CONTENT END -->
<footer class="fixed inset-x-0 bottom-0 z-50 bg-gray-700 h-7">
<div class="flex items-center justify-end px-8 pt-1">
<div class="text-sm text-white">{versionStr}</div>
</div>
</footer>
</div>
</div>
This cleaned it up nicely:
https://play.tailwindcss.com/Dbd5vnExhk
<div class="flex bg-gray-100 justify-center">
<div class="flex flex-col w-full max-w-5xl pb-7">
<nav class="sticky top-0 flex items-center justify-between bg-gray-700 text-white h-16 z-40 p-2">
<div class="flex w-1/3">
{Left}
</div>
<div class="flex justify-center w-1/3">
{Middle}
</div>
<div class="flex justify-end items-center w-1/3 gap-2">
{Right}
</div>
</nav>
<!-- CONTENT START -->
<div class="flex">
<div class="w-2/3">
<div class="sticky top-16 w-full h-20 bg-green-500">
Don't scroll
</div>
<div class="w-full h-[2000px] bg-gradient-to-b from-red-300 to-red-800">
Scroll
</div>
</div>
<div class="w-1/3 h-[calc(100vh-5.75rem)] sticky top-16 overflow-y-scroll overscroll-contain bg-pink-400">
<div class="h-[1000px]">
Scroll independently
</div>
</div>
</div>
<!-- CONTENT END -->
<footer class="fixed inset-x-0 bottom-0 z-50 bg-gray-700 h-7">
<div class="flex items-center justify-end px-8 pt-1">
<div class="text-sm text-white">{versionStr}</div>
</div>
</footer>
</div>
</div>
<div class="">
<div class="w-16 h-16 border-b-30 border-l-30 border-solid border-black">
<div class="h-16 w-16 border-t-30 border-r-30 bg-transparent"></div>
</div>
</div>
how to make a triangle with tailwindCss without plugin ??
You may try using transform:
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div class="w-16 overflow-hidden inline-block">
<div class=" h-11 w-11 bg-black rotate-45 transform origin-bottom-left"></div>
</div>
<div class="w-16 overflow-hidden inline-block">
<div class=" h-11 w-11 bg-black -rotate-45 transform origin-top-left"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black -rotate-45 transform origin-top-right"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black rotate-45 transform origin-top-left"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black -rotate-45 transform origin-bottom-right"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black rotate-45 transform origin-bottom-left"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black -rotate-45 transform origin-top-left"></div>
</div>
<div class="w-11 overflow-hidden inline-block">
<div class=" h-16 bg-black rotate-45 transform origin-top-right"></div>
</div>
You can also try using borders
tailwind playground
<!-- down -->
<div class="border-solid border-t-black border-t-8 border-x-transparent border-x-8 border-b-0"></div>
<!-- up -->
<div class="border-solid border-b-black border-b-8 border-x-transparent border-x-8 border-t-0"></div>
<!-- left -->
<div class="border-solid border-r-black border-r-8 border-y-transparent border-y-8 border-l-0"></div>
<!-- right -->
<div class="border-solid border-l-black border-l-8 border-y-transparent border-y-8 border-r-0"></div>
Maybe you want to use the triangle for tooltip. (such search got me here):
<div class="group relative mt-4 ml-4 inline-block">
<button type="button" class="rounded-md border border-neutral-600 px-1">...</button>
<!-- container for triangle and the menu ↓-->
<div class="invisible absolute left-0 -mt-[2px] flex flex-col group-focus-within:visible group-active:visible">
<div class="ml-2 -mb-[1px] inline-block overflow-hidden"> <!-- ← triangle container -->
<!-- triangle ↓ -->
<div class="h-3 w-3 origin-bottom-left rotate-45 transform border border-neutral-500 bg-neutral-100"></div>
</div>
<!-- menu ↓ -->
<div class="flex min-w-max flex-col rounded-md border border-neutral-500 bg-neutral-100 px-2 py-1">
<div class="cursor-pointer hover:underline">Do amazing stuff</div>
<div class="cursor-pointer hover:underline">Go back</div>
</div>
</div>
</div>
Demo on play.tailwindcss.com
Based on:
#temani-afif answer
https://github.com/tesar-tech/BlazorAndTailwind/blob/master/Articles/DropdownMenu/README.md
By pseudo-element (small triangle):
<script src="https://cdn.tailwindcss.com"></script>
<div>small triangle:</div>
<div class="flex gap-x-1">
<div class="before:content-['▴']"></div>
<div class="before:content-['▾']"></div>
<div class="before:content-['◂']"></div>
<div class="before:content-['▸']"></div>
</div>
By pseudo-element (normal triangle):
<script src="https://cdn.tailwindcss.com"></script>
<div>normal triangle:</div>
<div class="flex gap-x-1">
<div class="before:content-['▲']"></div>
<div class="before:content-['▼']"></div>
<div class="before:content-['◀']"></div>
<div class="before:content-['▶']"></div>
</div>
By border:
<script src="https://cdn.tailwindcss.com"></script>
<div>triangle by border</div>
<div class="flex gap-x-3">
<div class="w-0 h-0 border-8 border-solid border-transparent border-b-black"></div>
<div class="w-0 h-0 border-8 border-solid border-transparent border-t-black"></div>
<div class="w-0 h-0 border-8 border-solid border-transparent border-r-black"></div>
<div class="w-0 h-0 border-8 border-solid border-transparent border-l-black"></div>
</div>
By border (simplify):
<script src="https://cdn.tailwindcss.com"></script>
<div>triangle by border (simplify)</div>
<style type="text/tailwindcss">
#layer components { .triangle { #apply w-0 h-0 border-8 border-solid border-transparent } }
</style>
<div class="flex gap-x-3">
<div class="triangle border-b-black"></div>
<div class="triangle border-t-black"></div>
<div class="triangle border-r-black"></div>
<div class="triangle border-l-black"></div>
</div>