Anyway to customise or hotkey an element in Tailwind? - html

I just started using Tailwind and I liked it very much over traditional CSS. But I noticed that I have to repeatedly type in certain settings over the course of coding my JSX code.
I am wondering, is there anyway to shorten this task or more efficiently write Tailwind codes?
Currently I have the following - which I found to repeated itself many times: flex justify-center items-center. is there a way to hotkey it or define it somewhere as flex-center = flex justify-center items-center then I only need to call flex-center whenever I need it?
Full example below:
<template>
<div id="footerContainer" class="object-bottom">
<footer id="container" class="w-full h-12 lg:h-32 grid grid-rows-1 md:grid-cols-4 font-sans">
<!-- Mobile component -->
<div class="w-full h-full flex items-center md:hidden">
<div id="footbar" class="container grid gap-2 grid-cols-5 mb-2">
<div class="flex justify-center items-center">Home</div>
<div class="flex justify-center items-center">Sell</div>
<div class="flex justify-center items-center">post</div>
<div class="flex justify-center items-center">chat</div>
<div class="flex justify-center items-center"><ChatIcon class="h-6 w-6 text-gray-500" /></div>
</div>
</div>
</footer>
</div>
</template>
<script>
export default {
name: "FooterComponentv2",
};
</script>
<style scoped>
* {
border: 1px solid red;
}
</style>

Related

Hide Spinner element when loading api done typescript

How to hide the spinner when the API load? how to use the *ngIf for this type of problem?
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.0/angular.min.js"></script>
<div class="flex flex-col items-center mt-2">
<div >
<mat-progress-spinner mode="indeterminate">
<div class="text-7xl sm:text-8xl font-bold tracking-tight leading-none text-amber-500" >
{{weather.current.humidity}}
</div>
</mat-progress-spinner>
</div>
<div class="flex items-baseline justify-center w-full mt-5 text-secondary"></div>
</div>

Why my overflow-hidden is not working? Horizontal scroll bar is still visible

I am trying to move the rectangle to right to align it with image but when i do it there is a scroll bar below and i want to remove it
<section class="relative ">
<div class="container flex flex-col-reverse lg:flex-row items-center gap-12 mt-14 lg:mt-28">
<!-- Content -->
<div class="flex flex-1 flex-col items-center lg:items-start">
<h2 class="text-bookmark-blue text-3xl md:text-4 lg:text-5xl text-center lg:text-left mb-6">
A Simple Bookmark Manager
</h2>
<p class="text-bookmark-green text-lg text-center lg:text-left mb-6">
A clean and simple interface to organize your favourite websites. Open a mew tab and see it load instantly. Try it
for free.
</p>
<div class="flex justify-center flex-wrap gap-6">
<button type="button" class="btn btn-purple hover:bg-bookmark-white hover:text-black">Get it on Chrome</button>
<button type="button" class="btn btn-white hover:bg-bookmark-purple hover:text-white">Get it on Firefox</button>
</div>
</div>
<!-- Image -->
<div class="flex justify-center flex-1 mb-10 md:mb-16 lg:mb-0 z-10">
<img class="w-5/6 h-5/6 sm:w-3/4 sm:h-3/4 md:w-full md:h-full" src="/public/imgs/hero-bg.png" alt="" srcset="" />
</div>
</div>
<!-- Rounded Rectangle -->
<div
class="hidden md:block overflow-hidden bg-bookmark-purple rounded-l-full absolute h-80 w-2/4 top-32 right-0 lg:-bottom-28 lg:-right-36"
></div>
</section>
attached img for reference
https://prnt.sc/5Cf7y_5rUabl
overflow-hidden has to be applied to the container element (i.e. the parent), not to the element which you want to be cut off when going out of its container.
If you cannot apply overflow-hidden to the container for some reason, add another layer element between the original container and the element in question (i.e. a child of the original container, but at the same time parent of the to-be-cut element) and apply overflow-hidden to that inserted element.

How do I change scroll snap distance?

Hi I want to create a layout which emulates selecting filter in a camera app (like snapchat or Instagram) using just css and scroll snapping.
Reference:
I have achieved a solution but the problem is, it is not responsive. The snapping misaligns when the width is changed. So, my solution is only good for one resolution. Ideally, When the screen width is changed - the "filters" or circular divs should snap in the middle of the ring.
Here's my solution (using tailwindcss):
<div style="background: url('https://images.pexels.com/photos/13025682/pexels-photo-13025682.jpeg?auto=compress')" class="relative h-screen w-full overflow-hidden bg-cover">
<div class="absolute bottom-4 h-24 w-full">
<div class="flex w-full items-center justify-center">
<div class="h-16 w-16 rounded-full border-2"></div>
<div class="absolute left-0 w-full bg-red-500/20">
<div class="hide-scrollbar relative flex w-full snap-x snap-mandatory space-x-[4em] overflow-scroll pl-[22.10em] pr-[24em]">
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200"></div>
<div class="h-12 w-12 flex-shrink-0 snap-center rounded-full bg-blue-200">0</div>
</div>
</div>
</div>
</div>
</div>
Here's the above code in action: https://play.tailwindcss.com/VLhEtnYXmH
How do I make the UI responsive?
Well, I think your problem isn't exactly the snap distance but the way you handled this element...
You have to create kind of "dumb" items before and after your circle elements with a shrink-0 class :
<!-- Begin Dumb item -->
<div class="snap-center shrink-0">
<div class="w-dumb shrink-0"></div>
</div>
<!-- End Dumb item -->
and a width matching your screen (so, you need a css calc()).
Unfortunately, there's no such calc class in Tailwind that I know of...
So you have to create a custom class in this "dumb" element, before and after yours and add this css :
.w-dumb {
width: calc((50vw) - 3rem)
}
(Note that I added this custom class in my "dumb" html element
Here's a working sandbox :
https://play.tailwindcss.com/YUKxiYgu2l
(I took advantage of the opportunity to correct a little your structure and css classes)
Edit
Note that if you want to make the space bigger between your circle elements, you just have to change the tailwind class gap-6 to, let's say gap-10. But if you do so, you have to adapt the .w-dumb class and put a higher minus rem (width: calc((50vw) - 4rem for a gap-10 for example).

Overflow scroll on element

Here what I've now:
and how it should looks:
<div class="overflow-auto flex flex-col h-full">
<div class="flex flex-1 flex-col px-7 divide-y-2 divide-metal bg-white">
<div
v-for="item in items"
:key="item.id"
:item="item"
class="flex-1 py-4 lg:py-8"
/>
</div>
<div class="flex flex-col bg-white lg:bg-gray-light">
<div class="!bg-white lg:!bg-gray-light lg:border-b-2 lg:border-metal">
<template #content>
<h4
class="h4 uppercase !font-black !text-[26px] 2xl:!text-[36px] leading-10 tracking-[-0.43px]"
v-text="$t('We Also Recommend')"
/>
</template>
</div>
<div class="flex flex-col px-7 divide-y-2 divide-metal">
<div
v-for="product in recommendProducts"
:key="product.sku"
:item="product"
class="flex-1 py-4 lg:py-8"
/>
</div>
</div>
</div>
<div class="sticky top-0 bottom-auto">
<div class="p-10">
<div class="desktop-only flex justify-between items-center pb-10 uppercase">
<p
class="subtitle1"
v-text="$t('Subtotal')"
/>
<div
:value="totals.subtotal"
class="subtitle1"
/>
</div>
<div class="flex flex-col">
<div
v-text="$t('Proceed to Checkout')"
class="btn btn--lg btn--black mb-3.5 text-[15px]"
/>
</div>
</div>
</div>
</div>
And the problem is that bottom div should cover products and section 'We also recommend' with products should have scroll. Now bottom div extends beyond the view. On bottom div I've position: sticky and on section 'We also recommend' overflow: auto. Where's the problem and how to fix it?
If I understand your problem correctly, the bottom sheet does cover the last part of the scrolling content, right? There is an easy solution:
Just add
padding-bottom: XXpx; # XX == size of sticky bottom sheet
to the scroll container

Tailwind CSS - Creating a Kanban board

I'm trying to create a kanban board with tailwind css.
but I'm facing an issue when there are a lot of items in a list.
the list height grows and I'm not able to scroll. because I've added overflow-y-hidden to the container.
the max height of the list should not be greater the container and if there are more items I want to show a scroll bar instead.
How can I achieve this?
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div
class="absolute top-0 bottom-0 left-0 right-0 flex items-start pb-16 overflow-x-auto overflow-y-hidden select-none "
>
<!-- List Start -->
<div class="mx-1 bg-white border rounded-lg" style="min-width: 260px">
<!-- Header Start -->
<div class="flex items-center px-4 py-3 space-x-2 border-b">
<h2 class="text-sm font-medium uppercase">Approved</h2>
</div>
<!-- Header End -->
<!-- Items Start -->
<div
class="relative flex flex-col h-full px-4 py-4 space-y-3 overflow-auto bg-white "
style="background: white none repeat scroll 0% 0%"
>
<div
class="flex items-center w-full px-1 text-sm border rounded-lg shadow-sm cursor-pointer select-none group"
style="background: white none repeat scroll 0% 0%"
>
<button type="button" class="inline-block w-full py-2 text-left">
Create email templates for BPM
</button>
</div>
</div>
<!-- Items End -->
<!-- Add New Start -->
<div class="flex items-center px-4 pb-4">
<button
type="button"
class="flex items-center px-2 py-1 space-x-2 text-gray-700 rounded-md hover:bg-gray-100"
>
<span>Add New</span>
</button>
</div>
<!-- Add New End -->
</div>
<!-- List End -->
</div>
From the tailwind docs:
Use overflow-auto to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike .overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.
<div class="overflow-auto h-32 ...">Lorem ipsum dolor sit amet...</div>