Tailwind CSS utility class using a breakpoint is being overridden - tailwind-css

I am trying to add a different margin for large screens, and my breakpoints are not working. They work elsewhere except in this specific component.
My React.js component:
<Link to={`/dashboard/files/${name}`} className="hover:text-black">
<div className="bg-white h-24 w-28 rounded-2xl m-2 sm:m-4 inline-block p-1.5 cursor-pointer hover:shadow-md">
<div className="h-16 w-20 m-auto"> {icon} </div>
<Para content={name} />
</div>
</Link>
The m-4 class is being overridden by a value in _spacing.scss. I don't know what that file is or where it comes from. It's overriding the m-2 class with !important.

Have you tried overriding the value from the external SCSS file by adding your own "important" modifier? The exclamation point should be placed after the breakpoint variant value. For example:
<div className="sm:!m-4 ..." />
See: https://tailwindcss.com/docs/configuration#important-modifier
If you run into a lot of problems with SCSS overrides and want to ensure that your Tailwind utility classes always apply, you could instead add the important option to your tailwind.config.js:
module.exports = {
important: true,
}

Related

Responsive tailwind css (padding and flex-direction) not applied to large screens

Im trying to get some advice on Tailwind with div positioning using custom media breaks. Currently at screens over 350px(xs) the homepage layout is flex with flex-col direction. Yet when I set it to flex-row (flex) for large screens over 1100px(lg), it remains as flex-col and one of the flex children is hiding the other.
When I test to see if my custom screens work by changing font-color at each break (xs-lg), it works. Meaning my screens are set up fine. It just seems like its not registering changes in positioning particularly with flex but also with padding interestingly.
Sorry if this is obvious but I have read the tailwind docs and since they work with color changes It means the breaks are set up right. So I'm probably just missing something obvious.
```javascript
export default function HomeHero(){
return(
<div className={styles.HeroContainer}>
<div className={styles.HeroText}>
<div className={styles.title}>Stay connected off-grid</div>
<div className={styles.text}>paragraph text</div>
<form className={styles.form} action="/send-data-here" method="post">
<input type="text" className={styles.input} name="first" placeholder="Email Address"/>
<input type="text" className={styles.input} name="last" placeholder="Password"/>
<div className={styles.Button}><button type="submit">Log In</button></div>
<div className={styles.forgot}><Link href="/forgotpassword">Forgot your password?</Link></div>
</form>
</div>
<div className={styles.HeroImage}></div>
</div>
)
}
const styles = {
HeroContainer: 'flex xs:flex-col lg:flex-col lg:min-h-screen',
HeroText: 'flex flex-col border-2 text-left xs:p-10 md:p-24 w-1/3 lg:mt-12 lg:pr-36 lg:pl-36',
HeroImage: 'flex w-2/3 bg-hero bg-center bg-contain bg-no-repeat bg-top-32 self-stretch min-h-[500px]'
}
At first I was stumped until I realized that the flex-col on HeroText wasn't doing anything without it being a flex container. Now that I'm looking at it and your example, I think that is the problem.
Your flex direction classes are on the container which is just setting the flex direction on the HeroText div. You need to move those flex direction utilities to HeroText. Here's a Tailwind Play example: https://play.tailwindcss.com/MmfOrXgVa0 (OLD LINK)
You probably also want to rethink the styles on HeroImage. Seems like you'd want to absolutely position that.
UPDATE BASED ON COMMENTS:
Your comment changes things. The flex-direction was being updated with your with the code you had. You still had some extra classes, but that didn't stop it from working. I believe, the real issue was around using lg:bg-hero. Unless you added that as something in your config, that class wouldn't do anything, and it wouldn't be connected to the lg breakpoint.
Also, you are defining flex-1 and widths on the two elements, and these are conflicting with each other with the flex-1 winning. Because of this, when it was full screen, the background was only 50% wide, and since your content wasn't wide enough to wrap, you weren't seeing it.
If you fix those things, you should be good to go. Here is a working example in Tailwind Play: https://play.tailwindcss.com/kF7mi27UUC
Also, here would be some updated classes for your JS. I added a few classes to the HeroImage class so that it would show up:
const styles = {
HeroContainer: 'flex flex-col lg:flex-row lg:min-h-screen',
HeroText: 'flex flex-col text-left xs:p-10 md:p-24 lg:w-1/3 lg:mt-12 lg:pr-24 lg:pl-24',
HeroImage: 'lg:w-2/3 bg-center border-2 bg-cover bg-top-32 self-stretch bg-black min-h-[200px]',
}

tailwind form not positioning properly as fixed element

I'm using tailwind css to style a little angular app, the problem is:
i want my form to have a fixed position at the bottom of the page but it seems that classes like "top-100 left-50" are not working
home-component.html
<main class="container bg-green-200 h-full m-auto">
<app-search class="fixed top-100"></app-search>
<app-fruits-cards></app-fruits-cards>
</main>
searchbar-component.html:
<form *ngIf="searchForm" [formGroup]="searchForm" (ngSubmit)="onSubmit()" class="bg-slate-100 rounded p-3">
<label for="searchInput">Search</label>
<input formControlName="fruitName" type="text" id="searchInput" class=""/>
<button type="submit" class="rounded-full">search</button>
</form>
I actually tried to use the "top-100" class into the form element directly but it still doesn't work, what am I doing wrong here?
Try adding position relative to the container
Also i'm not sure about top-100 ...
check here what values are allowed with the classes of top ..
https://tailwindcss.com/docs/top-right-bottom-left
There is no default defined class top-100 the most near to it is top-96 but you can define your default in tailwind.config file or use custom value like top-[100px]
Read about:
Adding arbitrary values here: https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values
Defining classes in the config file here: https://tailwindcss.com/docs/configuration

Is there a way to chain multiple tailwind css classes on a single hover instance?

I was wondering if there is a way to chain multiple tailwind css classes on a single hover instance on an html element instead of using multiple hover instances.
For instance instead of this
<button class="hover:bg-blue-900 hover:text-white"></button>
whether you can have this or something else
<button class="hover:bg-blue-900:text-white"></button>
No there isn't. As from the docs(https://tailwindcss.com/docs/hover-focus-and-other-states), you can see they themselves add multiple classes for focus/hover.
However you can create reusable styles to counter this
Sadly it seems not. Maybe something that should be suggested to the team
I was trying to do something similar, i wanted the text to change color when hover the div.
searching in the docs i found the 'group' that helped me:
https://tailwindcss.com/docs/hover-focus-and-other-states#styling-based-on-parent-state
i tried different types of hover like:
hover:bg-green-600 text-gray-50
hover:[bg-green-600 text-gray-50]
hover:(bg-green-600 | text-gray-50)
Maybe you can try wrapping the button in a div and add the group class
my code before, did not work like this
<Link to='/home'>
<div className="p-2.5 mt-3 flex items-center rounded-md px-4 duration-300 cursor-pointer hover:(bg-green-600 text-gray-50)">
<span className="text-[15px] ml-4 text-gray-500 font-bold">Home</span>
</div>
</Link>
after using gruop
<Link to='/home' className='group'>
<div className="p-2.5 mt-3 flex items-center rounded-md px-4 duration-300 cursor-pointer group-hover:bg-green-600" >
<span className="text-[15px] ml-4 text-gray-500 group-hover:text-gray-50 font-bold">Home</span>
</div>
</Link>
with group when i hover the div it also change the span text color, like this the cursor don't need to be right on top of the word to make hover work.
but I still wish there was a way to put more than one class on the same hover, I hope they add it in the future...
hope it may help
I stumbled upon the same issue and was going to write a Tailwind plugin for that but it turns out that it's hard to mess with the rules they have set, you can only extend it by adding new variants and utilities but cannot do something like hover:(text-white bg-red-500).
However, I did find out about twin.marco that has this variant groups feature so check do check that out.

How to use Tailwind background-image in SvelteKit

https://tailwindcss.com/docs/background-image#arbitrary-values
this is how I want to use Tailwind bg-image feature. This does not work using SvelteKit next 160 and Tailwind 3.0.9.
Code:
<script>
import globe from '$assets/bg/bg_globe2.png'
</script>
<div
class={`flex flex-col bg-primary-dark h-64 overflow-hidden bg-no-repeat bg-[right_-14rem_bottom_-10rem] bg-[url('${globe}')]`}
>
//children
</div>
the bg-[right_-14rem_bottom_-10rem] class works without problems, so I assume Tailwind has problem with Svelte file paths?
EDIT:
output from console.log(globe) is src/assets/bg/bg_globe2.png.
❌ Arbitrary values cannot be computed from dynamic values
<div class="bg-{ userThemeColor }"></div>
✅ Use inline styles for truly dynamic or user-defined values
<div style="background-color: { userThemeColor }"></div>
https://v2.tailwindcss.com/docs/just-in-time-mode#arbitrary-value-support
Tailwind needs to find the full text value in your code to be able to generate the utility classes.

How to override SASS spacing in Bootstrap 4

Because Bootstrap 4 uses SASS for components like cards, I'm having trouble overriding it in CSS since I haven't used SASS before.
I see ways to override configuration files in a server node.js environment, but for a basic index.html file linked to Bootstrap and a custom CSS file, how do you go about setting margin bottom to 0?
HTML here:
<div class="card mb-3" id="sheet-footer">
<div class="card-header text-center">`=
<h3 class="card-title">
Content
</h3>
</div>
</div>
Chrome dev tools show the following:
.mb-3, .my-3 {
margin-bottom: 1rem!important;
}
Any attempts to override margin-bottom (even with the terrible HTML style tag) don't beat this rule - what's the proper way to override this?
Thanks in advance.
If you don't want a margin bottom remove the class mb-3
If you only want a margin bottom on specific breakpoints bootstrap 4 allows mb-md-3
see https://getbootstrap.com/docs/4.0/utilities/spacing/

Resources