how to darken the image on hover in tailwind - hover

I am new to tailwind and I am trying to make the image darker on hover.
Here is my config.js
theme: {
extend:{
backgroundImage: (theme) => ({
video: "url('./bg-img.jpg')",
})
}
},
variants: {
boxShadow:["responsive", "hover", "focus"]
}
and here is my code:
<div className=" h-80 my-4 w-64 rounded-md p-4 bg-video bg-cover bg-center shadow-lg cursor-pointer group hover:bg-black transition-all duration-1000">
<h1 className="uppercase text-2xl text-golden font-black group-hover:text-secondary transition-all duration-500">
video
</h1>
</div>

You could try putting a div inside and then use the background opacity when hovering it.
Your HTML will be something like this
<div class="h-80 my-4 w-64 rounded-md bg-video bg-cover bg-center shadow-lg cursor-pointer">
<div class="bg-black bg-opacity-0 p-4 w-full h-full hover:bg-opacity-50 transition-all duration-1000">
<h1 class="uppercase text-2xl text-golden font-black group-hover:text-secondary transition-all duration-500">video</h1>
</div>
</div>
And the Tailwind config file
// tailwind.config.js
module.exports = {
theme: {
extend: {
backgroundImage: {
video: "url('./bg-img.jpg')", },
},
},
variants: {
extend: {
backgroundImage: ['hover'],
}
},
}
You can check the demo here: https://play.tailwindcss.com/hfCerQQvHQ

There are several options for you to accomplish what you want.
Using:
filter
backdrop-filter.
I'm sharing with you the filter example.
<div class="min-h-screen flex items-center justify-center bg-royalblue">
<div class="filter hover:grayscale hover:contrast-200">
<img src="https://loremflickr.com/cache/resized/65535_51423949778_4bccb1beec_c_500_500_nofilter.jpg" alt="">
</div>
</div>
https://codepen.io/victoryoalli/pen/mdBVjbb

Related

How can I change the background video in my React.js portfolio to a video?

I am a beginner developer who is currently trying to build a simple portfolio website to showcase my projects and skills. I have been watching some tutorials on YouTube to relearn web development, as it's been about 5 years since I last coded a website. I am currently stuck on a specific task, which is importing videos as backgrounds for multiple pages including the main page and the project pages. I am having a hard time understanding how to properly import and implement videos as backgrounds and would greatly appreciate any help or guidance on this issue.
const Main = () => {
return (
<div className="flex items-center justify-center h-screen mb-12 bg-fixed bg-center bg-cover custom-img">
<div id="home" className="w-full h-screen text-center">
<div className="max-w-[1240px] w-full h-full mx-auto p-2 flex justify-center items-center">
<div className="">
<p className="uppercase text-lg tracking-widest text-black">
My name is
</p>
<h1 className="py-4 text-gray-700">
<span className="text-[#cca454]"> Abiola Batiste</span>
</h1>
<h1 className="py-1 text-black ">
<TypeAnimation
sequence={[
"Digital Animation Major", // Types 'One'
2500, // Waits 1s
"Enviroment Designer", // Deletes 'One' and types 'Two'
2500, // Waits 2s
"Photographer",
2500, // Types 'Three' without deleting 'Two'
() => {
console.log("Done typing!"); // Place optional callbacks anywhere in the array
},
]}
wrapper="div"
cursor={true}
repeat={Infinity}
style={{ fontSize: "0.5em" }}
/>
<div className="text-center "></div>
</h1>
{/*spacers for the button downwards */}
<div className="relative w-full pb-10"></div>
<div className="flex items-center justify-between max-w-[330px] m-auto py-4 position-absolute bottom-0">
<a
href="https://www.linkedin.com/in/abiola-batiste-4827a9189/"
target="_blank"
rel="noreferrer"
>
<div className="rounded-full p-4 cursor-pointer hover:scale-110 ease-in duration-300">
<FaLinkedinIn />
</div>
</a>
<a
href="https://www.instagram.com/the_rastudios/"
target="_blank"
rel="noreferrer"
>
<div className="rounded-full p-4 cursor-pointer hover:scale-110 ease-in duration-300">
<FaInstagram />
</div>
</a>
<Link href="/#contact">
<div className="rounded-full p-4 cursor-pointer hover:scale-110 ease-in duration-300">
<AiOutlineMail />
</div>
</Link>
<Link href="/resume">
<div className="rounded-full p-4 cursor-pointer hover:scale-110 ease-in duration-300">
<BsFillPersonLinesFill />
</div>
</Link>
</div>
</div>
</div>
</div>
</div>
);
};
return (
<div className="flex items-center justify-center h-screen mb-12">
<video autoPlay loop muted object-fit="cover" className="w-full h-full">
<source src="public\assets\images\japan.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
<div id="home" className="w-full h-screen text-center">
I took this approach but all it did was push my contents to the right, and made the bg white?

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>

Tailwind CSS hide div on hover not hiding

I have a collection of images that appear as cards. The cards have text below them. I am trying to hide the text and show the image only using tailwind v2 with no luck.
My code :
<div class="group max-w-sm bg-white m-4 rounded-lg border border-gray-200 shadow-md dark:bg-gray-800 dark:border-gray-700">
<a href="#">
<img class="rounded-t-lg w-full h-64 object-cover" src="images/care.webp" alt="" />
</a>
<div class="p-1 visible group-hover:invisible">
<p class="visible group-hover:invisible text-center mb-3 font-normal text-gray-700 dark:text-gray-400">CARE</p>
</a>
</div>
</div>
<!-- end of card -->
<!-- Card -->
<div class="group max-w-sm bg-white m-4 rounded-lg border border-gray-200 shadow-md dark:bg-gray-800 dark:border-gray-700">
<a href="#">
<img class="rounded-t-lg w-full h-64 object-cover" src="images/kindness.jpg" alt="" />
</a>
<div class="p-1 invisible group-hover:visible">
<p class="invisible group-hover:visible text-center mb-3 font-normal text-gray-700 dark:text-gray-400">KINDNESS</p>
</a>
</div>
</div>
Any recommendations/advise on what i am doing wrong will be appreciated.
I have referenced documentation and stackoverflow with no luck
in your documentation link at the end there is such a code
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
visibility: ['hover', 'focus'],
}
}
}
so you have to add these parameters to your tailwind.config.js to make it work
and use these classes visible hover:invisible

Anyway to customise or hotkey an element in Tailwind?

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>

TailwindCSS in Next.JS not rendering properly in Webkit

I am using TailwindCSS in a Next.JS project with postcss and autoprefixer. The issue here is it renders fine in Desktop and Chrome for Android, and Firefox. In iOS though both on Safari as well as chrome, the UI gets messed up.
I tried a lot of autoprefixer configs. None of them worked. This problem exists only with webkit. I thought maybe because of the flex, but other flexes on the same page work fine.
Here's the Minimal repo to reproduce the error.
https://github.com/RohithCIS/tailwind-nextjs-webkit-issue
I have attached the images below.
Here's my configs and thanks for the help.
// postcss.config.js
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer')
]
}
// tailwind.config.js
module.exports = {
theme: {
extend: {
borderRadius: {
'xl': '30px'
},
colors: {
grapefruit: '#da4453',
bittersweet: '#e9573f',
bluejeans: '#4a89dc',
lavander: '#967adc',
sunflower: '#f6bb42',
grass: '#8cc152',
pinkrose: '#d770ad',
lightgray: '#e6e8ed',
mint: '#37bc9b',
aqua: '#3bafda',
mediumgray: '#aab2bd',
darkgray: '#434a54'
}
},
},
variants: {},
plugins: []
}
// next.config.js
const withSass = require('#zeit/next-sass');
module.exports = withSass({});
<section className="flex flex-col items-center lg:mt-5">
<div className="max-w-1200">
<div className="flex flex-col lg:flex-row justify-between lg:p-3 w-full">
{/* PREVIEW PANE */}
<div style={{ flexBasis: 0, flexGrow: 3 }}>
<CarouselProvider
naturalSlideWidth={1}
naturalSlideHeight={1}
totalSlides={3}
className="flex flex-col-reverse lg:flex-row"
>
<div className="flex flex-row lg:flex-col p-3 lg:p-0">
<Dot slide={0} className="thumb-preview border border-gray-300 hover:border-pinkrose rounded lg:mb-3 mr-3 lg:mr-0">
<img className="rounded object-cover h-full w-full" src="https://images.cbazaar.com/images/stones-embellished-royal-blue-saree-sadsfcns2198-u.jpg"></img>
</Dot>
<Dot slide={1} className="thumb-preview border border-gray-300 hover:border-pinkrose rounded lg:mb-3 mr-3 lg:mr-0">
<img className="rounded object-cover h-full w-full" src="https://www.jivaana.com/cache/9d/90/rose-red-saree-and-blush-pink-crop-top_saree_red-baby-pink_151186283056-9d90b1cb5f0ccd4306a0ba39058f8571.jpg"></img>
</Dot>
<Dot slide={2} className="thumb-preview border border-gray-300 hover:border-pinkrose rounded lg:mb-3 mr-3 lg:mr-0">
<img className="rounded object-cover h-full w-full" src="https://images.cbazaar.com/images/stones-embellished-royal-blue-saree-sadsfcns2198-u.jpg"></img>
</Dot>
</div>
{/* <div>
<img className="object-contain" src="https://images.cbazaar.com/images/stones-embellished-royal-blue-saree-sadsfcns2198-u.jpg"></img>
</div> */}
<div className="w-full lg:mx-3">
<Slider>
<Slide index={0}><ImageWithZoom src="https://images.cbazaar.com/images/stones-embellished-royal-blue-saree-sadsfcns2198-u.jpg"></ImageWithZoom></Slide>
<Slide index={1}><ImageWithZoom src="https://www.jivaana.com/cache/9d/90/rose-red-saree-and-blush-pink-crop-top_saree_red-baby-pink_151186283056-9d90b1cb5f0ccd4306a0ba39058f8571.jpg"></ImageWithZoom></Slide>
<Slide index={2}><ImageWithZoom src="https://images.cbazaar.com/images/stones-embellished-royal-blue-saree-sadsfcns2198-u.jpg"></ImageWithZoom></Slide>
</Slider>
</div>
</CarouselProvider>
</div>
{/* DETAILS PANE */}
<div style={{ flexBasis: 0, flexGrow: 4 }} className="flex flex-col p-5 pt-0 rounded-lg">
<span className="text-base lg:text-xl text-darkgray">Blue Gray and Gold Coloured Netted Cotton Saree | Straight from Weavers</span>
<div className="flex flex-col lg:flex-row">
<div className="flex flex-col">
<div className="flex justify-between flex-row-reverse items-start lg:flex-col">
<div className='flex flex-row items-center'>
<StarRatingComponent className="text-3xl"
name="rate1"
starCount={5}
value={4}
starColor={'#d770ad'}
/>
<span className="text-dark-gray ml-5 text-xs">231 Ratings<br />10 Reviews</span>
</div>
<div>
<div className="lg:mt-5">
<span className="text-4xl text-pinkrose">₹{store.price}</span>
<span className="text-gray-500 line-through ml-2">₹{store.originalPrice}</span>
</div>
<span className="text-darkgray text-sm">+ ₹100 Shipping</span>
</div>
</div>
<span className="text-xs font-bold mt-3 lg:mt-5 p-1 text-darkgray">Select Variant</span>
<div className="variants flex flex-row items-center text-darkgray">
<div>
<input className="variant hidden" type="radio" name="variant" value="variant1" id="variant1" onChange={this.handleVariantChange} defaultChecked></input>
<label htmlFor="variant1">
<span className="text-xs border border-pinkrose p-1 mr-2 rounded cursor-pointer">With Kit</span>
</label>
</div>
<div>
<input className="variant hidden" type="radio" name="variant" value="variant2" id="variant2" onChange={this.handleVariantChange}></input>
<label htmlFor="variant2">
<span className="text-xs border border-pinkrose p-1 mr-2 rounded cursor-pointer">Without Kit</span>
</label>
</div>
</div>
</div>
<div className="flex flex-row lg:flex-col items-center justify-between lg:justify-center mt-5 lg:mt-0" style={{ flexGrow: 1 }}>
<button className="text-white bg-pinkrose hover:bg-lavander hover:shadow-none p-3 rounded mb-3 shadow-lg w-full lg:w-48 mr-2 lg:mr-0">Add to Cart</button>
<button className="text-white bg-pinkrose hover:bg-lavander hover:shadow-none p-3 rounded mb-3 shadow-lg w-full lg:w-48 ml-2 lg:ml-0">Buy Now</button>
</div>
</div>
<div className="flex flex-col mt-5 text-darkgray">
<span className="text-xs font-bold p-1">Description</span>
<p className="p-1 text-sm">This is a beautiful netted cotton saree, with patch work along the zari embedded with beautiful gold and silver stone work. Comes with a contast blouse. The suggested designs below work really well with the saree.</p>
</div>
</div>
</div>
<div className="text-darkgray p-5 pt-0 flex flex-col lg:flex-row">
{/* SPECS PANE */}
<div style={{ flexBasis: 0, flexGrow: 3 }}>
<span className="text-xs font-bold p-1">Specifications</span>
<table className="border border-gray-400 border-collapse w-full mt-5">
<thead>
<tr>
<th className="p-1 border-b border-gray-400 text-left text-sm bg-gray-200">Specification</th>
<th className="p-1 border-b border-gray-400 text-left text-sm">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td className="p-1 text-sm bg-gray-200">Length</td>
<td className="p-1 text-sm">8 Yards</td>
</tr>
<tr>
<td className="p-1 text-sm bg-gray-200">Cloth Type</td>
<td className="p-1 text-sm">Netted Cotton</td>
</tr>
</tbody>
</table>
</div>
{/* REVIEWS PANE */}
<div className="mt-5 lg:p-5 lg:pt-0 lg:mt-0" style={{ flexBasis: 0, flexGrow: 4 }}>
<span className="text-xs font-bold p-1">Reviews</span>
<div className="flex flex-row py-5 items-start border-b border-gray-400">
<div className="flex flex-col items-center">
<img src="https://i.pravatar.cc/300" className="w-10 h-10 rounded-full" />
</div>
<div className="flex flex-col px-3 flex-grow">
<span className="font-bold text-sm">Write Your Review</span>
<span className="text-xs">John Doe</span>
<input placeholder="Review Title" className="rounded bg-gray-200 text-sm mt-3 p-2"/>
<textarea placeholder="Write your Review here" className="rounded bg-gray-200 text-sm mt-3 p-2" rows="3"/>
<button className="rounded shadow-lg bg-pinkrose text-white px-2 py-1 w-1/3 lg:w-1/5 mt-3">Submit</button>
</div>
</div>
<div className="flex flex-row py-5 items-start border-b border-gray-400">
<div className="flex flex-col items-center">
<img src="https://i.pravatar.cc/300" className="w-10 h-10 rounded-full" />
<span className="px-2 mt-2 rounded bg-sunflower font-bold text-white text-sm">3.5 ★</span>
</div>
<div className="flex flex-col px-3">
<span className="font-bold text-sm">Awesome Saree, Thoroughly Enjoyed Wearing It.</span>
<span className="text-xs">John Doe</span>
<p className="text-sm mt-1">
This was a great saree. I gifted it to myself on my birthday. Prompt Delivery and Great Collection.
</p>
</div>
</div>
</div>
</div>
</div>
</section>
Found the problem. The CSS in JS was the problem. With Tailwind's flex-col and this, safari shrunk the content to fit it. Hence the overlap. Removed CSS in JS and moved it to a Sass file with media queries and loaded them with next-sass.
<div style={{ flexBasis: 0, flexGrow: 3 }}>
...
</div>
<div style={{ flexBasis: 0, flexGrow: 4 }}>
...
</div>
Totally my fault.