Why isn't tailwind CSS working on the card component? - html

Whenever I delete something off of the css for the card component and readd it, it works but whenever I restart my project, it stops working.
I've already tried adding the html directory file to the content section of the tailwind.config file.
What it is supposed to look like:
How it is looking:
In src/index.css:
#import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');
#tailwind base;
#tailwind components;
#tailwind utilities;
In src/app.js:
import { BrowserRouter } from "react-router-dom";
import { HashLink as Link } from "react-router-hash-link";
import Header from "./pages/Header";
import About from "./pages/About";
import Resume from "./pages/Resume";
import Projects from "./pages/projects";
import Contact from "./pages/Contact";
import Card from "./card/card"
function App() {
return (
<BrowserRouter>
<Header/>
<About/>
<Resume/>
<Card
img = "./img/resume.png"
title = "Resume"
description = "d resume"
button = "download"
/>
<Projects/>
<Contact/>
</BrowserRouter>
)
}
export default App;
In src/card/card.jsx:
import React from "react";
export default function Card(props) {
return (
<div class="min-h-screen bg-orange-100 " className="card">
<div
class="w-60 p-2 bg-white rounded-xl transform transition-all hover:-translate-y-2 duration-300 shadow-lg hover:shadow-2xl"
className="card_body"
>
<img class="h-40 object-cover rounded-xl" src={props.img} />
<div class="p-2"></div>
<h2 class="font-bold text-lg mb-2 " className="card_title">
{props.title}
</h2>
<p class="text-sm text-gray-600" className="card_description">
{props.description}
</p>
<div class="m-2">
<button
class="text-white bg-sky-500 px-3 py-1 rounded-md hover:bg-purple-700"
className="card_btn"
>
{props.button}
</button>
</div>
</div>
</div>
);
}
In tailwind.config.js:
/** #type {import('tailwindcss').Config} */
module.exports = {
purge: ["*"],
content: ["./src/**/*.{js,jsx,ts,tsx}", "./*/*.html"],
theme: {
extend: {
fontFamily: {
inter: "Inter",
},
},
},
plugins: [],
};

It looks like you never import the CSS file. Try adding import "./index.css" in the src/App.js file

I got it to work when I got rid of all of the "className" on ./card/card but I am not sure why.

Related

Styles not applying on web from tailwindcss

I followed the tutorial perfectly and made a website while using the live server extension and it was applying. I use Chrome, Edge and Opera to check the .html file itself but no style was applied in the matter of fact it still shows as applied in the live server extension
The files
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/dist/output.css" rel="stylesheet" />
</head>
<body class="m-0 bg-blue-500 p-0">
<nav class="m-0 h-full w-full space-x-4 border bg-blue-400 p-6">
<h1 class="text-3xl font-bold drop-shadow-md md:filter-none">
Safer Internet
</h1>
<div
class="absolute top-7 right-14 space-x-10 stroke-2 font-extrabold hover:stroke-black"
>
<button
class="position inline-block text-right duration-700 hover:text-white"
>
Home
</button>
<button
class="position inline-block text-right duration-700 hover:text-white"
>
More
</button>
<button
class="position inline-block text-right duration-700 hover:text-white"
>
About
</button>
</div>
</nav>
<div>
<p
class="absolute left-64 top-2/4 translate-x-2/4 translate-y-2/4 text-center text-xl font-bold"
>
To be able to know how to be safe on the internet click the button
bellow.
</p>
<div
class="relative top-96 flex translate-y-2/3 items-center justify-center text-center"
>
<button
class="relative top-9 w-1/6 rounded-xl bg-blue-900 p-4 font-extrabold duration-700 hover:bg-black hover:text-white"
>
More
</button>
</div>
</div>
</body>
</html>
tailwind.config.js:
module.exports = {
content: ["./src/**/*.{html,js}", "./public/*.html"],
theme: {
extend: {},
},
plugins: [],
}
style.css:
#tailwind base;
#tailwind components;
#tailwind utilities;
I tried everything and it didn't work and I expected the styles to apply on my browser.
Proper approach to follow when using Tailwind-CLI
1. Know about your file structure. Use:
public
|_ tailwind_base.css
👆 File from which the output.css is produced
#tailwind base;
#tailwind components;
#tailwind utilities;
|_ output.css
src
|_ index.html
👆 Link with the output.css using
<link href="../public/output.css" rel="stylesheet" />
Watch it as
npx tailwindcss -i ./public/tailwind_base.css -o ./public/output.css --watch
Specify your html/js in tailwind.config.js
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
};
Use tailwindcss classes happily in your index.html file 😇

How to stop other classes from changing colour when changing an "HTML" tag background colour

Hello I am trying to change the background of my page using the following code in a file called
Survey.module.css:
html {
background-image: linear-gradient( 94.3deg, rgba(26,33,64,1) 10.9%, rgba(81,84,115,1) 87.1% );
}
I've imported the CSS into my react component using the following import statement: import style from './Survey.js'
The code in Survey.js is below
import React from 'react'
import { Container, Col, Row } from 'react-bootstrap'
import style from './Survey.module.css'
function Survey() {
return (
<html>
<div>
<h1 className="display-5 text-center mt-5 text-white">Tell us about yourself</h1>
<div className={`${style.container} d-flex justify-content-center align-items-center`}>
<div className='row justify-content-md-center'>
<div className='col col-lg-5 shadow p-3 mb-5 bg-white rounded'>
<img src='https://static.toiimg.com/photo/msid-77430626/77430626.jpg?228049' className='rounded img-fluid'></img>
</div>
<div className='col col-lg-5 shadow p-3 mb-5 bg-white rounded'>
<h1></h1>
</div>
</div>
</div>
</div>
</html>
)
}
export default Survey
My issue is that when I change the background in CSS with the above code, the background of other pages in my project also change. All those pages import their CSS files using ***.module.css
I tried to use CSS modules to avoid this problem but I am still encountering it. Any advice?
Give your html class so your css doesn't affect to other page.
html.survey {
background-image: linear-gradient( 94.3deg, rgba(26,33,64,1) 10.9%, rgba(81,84,115,1) 87.1% );
}
import React from 'react'
import { Container, Col, Row } from 'react-bootstrap'
import style from './Survey.module.css'
function Survey() {
return (
<html className="survey">
<div>
<h1 className="display-5 text-center mt-5 text-white">Tell us about yourself</h1>
<div className={`${style.container} d-flex justify-content-center align-items-center`}>
<div className='row justify-content-md-center'>
<div className='col col-lg-5 shadow p-3 mb-5 bg-white rounded'>
<img src='https://static.toiimg.com/photo/msid-77430626/77430626.jpg?228049' className='rounded img-fluid'></img>
</div>
<div className='col col-lg-5 shadow p-3 mb-5 bg-white rounded'>
<h1></h1>
</div>
</div>
</div>
</div>
</html>
)
}
export default Survey
How about creating a div with a your preferred className that wraps the rest of the content and you can add your css styling like background-image to it. I don't get logic behind setting a background-image on the entire html document.
<div className={styles.surveyContainer}>
<div className={styles.content}>
...rest of the content
</div>
</div>

How to "stick" icon next to the scrollbar and make it always be there (even if scrolling)?

I've been trying to put the icon very next to the scroll bar in my react page. Now I can't find a way to properly align items in the way I want.
Now here is what I got:
Now red square is where my icon is and green is where I want it to be. Also I want to be able to scroll page with icon still being there(so I want it always to be there). This will be my filtering inputs.
Here is my return of component:
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import Form from 'react-validation/build/form';
import ArticleService from '../../services/article.service';
//import Filter from '../Filter/Filter';
import {
MDBDropdown,
MDBDropdownToggle,
MDBDropdownMenu,
MDBDropdownItem,
} from 'mdbreact';
import { Pagination } from 'semantic-ui-react';
import numeral from 'numeral';
const Dashboard = () => {
.....
return (
<div>
{loading ? (
<div className='text-white'>
<div className='float-right'> //here is where I'm using the icon
<MDBDropdown dropleft>
<MDBDropdownToggle caret color='#ffffff'>
<i className='fas fa-chevron-left'></i>
</MDBDropdownToggle>
<MDBDropdownMenu>
<MDBDropdownItem>
<p>Input1</p>
</MDBDropdownItem>
<MDBDropdownItem>
<p>Input2</p>
</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</div>
<div className='container'>
{renderHeader()}
<div className='text-center'>
<Form className='input-group mb-3' onSubmit={addFilter}>
{' '}
<input
type='text'
className='form-control text-center transparent-input'
placeholder='Unesite željenu lokaciju na području grada Sarajeva npr. Dobrinja'
aria-label='Unesite željenu lokaciju na području grada Sarajeva npr. Dobrinja'
aria-describedby='basic-addon2'
value={location}
onChange={onChangeLocation}
/>
<div className='input-group-append'>
<button
className='btn btn-grad rounded'
onClick={submitNameFilter}
>
<i className='fas fa-search-location'></i>
</button>
</div>
</Form>
</div>
<div className='d-flex'>
<div className='row row-cols-1 row-cols-md-3 custom-p'>
{content.map(card)}
</div>
<div></div>
</div>
</div>
<div className='mb-5 mt-5 text-center'>
<Pagination
totalPages={Math.ceil(total / 15)}
onPageChange={(e, d) => {
parsedUrl.set('page', d.activePage);
const pushPageToURL = parsedUrl.toString();
setPage(d.activePage);
window.history.pushState(null, null, `?${pushPageToURL}`);
}}
activePage={page}
/>
</div>
</div>
) : (
<div className='spinner-border text-primary text-center' role='status'>
<span className='sr-only'>Loading...</span>
</div>
)}
</div>
);
};
export default Dashboard;
Note that I'm using bootstrap.
you have to use the fixed position, Which in bootstrap becomes position-fixed || fixed-top.
pure css example:
#icon {
position: fixed;
top: 0;
}
take a look at this example:
https://getbootstrap.com/docs/4.0/examples/navbar-top-fixed/

Navbar transition in tailwindcss

I have a navbar and I want that when someone clicks on the button, it will be open with transition in tailwindcss.
const bar_btn = document.getElementById('BAR-BTN');
const mobileMenu = document.getElementById('mobileMenu')
bar_btn.addEventListener(
'click',
function() {
mobileMenu.classList.toggle('w-0')
mobileMenu.classList.toggle('h-0')
}
)
<nav>
<div>
<button id='BAR-BTN'><i class="fas fa-bars fa-2x"></i></button>
</div>
<ul class="transition-transform ease-linear h-0 w-0 delay-1000 duration-1000"
id="mobileMenu">
<li>test-1</li>
<li>test-2</li>
<li>test-3</li>
</ul>
</nav>
This is my HTML and javascript code and it doesn't work.
I could not find a way to give transition to height property(which we can in pure css) so i used scale to give a transition effect
See if it helps
const bar_btn = document.getElementById('BAR_BTN');
const mobileMenu = document.getElementById('mobileMenu')
bar_btn.addEventListener('click',function()
{
mobileMenu.classList.toggle('transform');
}
);
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<nav>
<div>
<button id="BAR_BTN" class="px-10 py-2 mt-10 mx-10 w-1/4 hover:bg-green-300 bg-green-200 transition-all">button</button>
</div>
<ul id="mobileMenu" class="mx-10 p-5 border-4 border-black overflow-hidden text-xl w-1/4 origin-top duration-300 scale-y-0" >
<li>Test-1</li>
<li>Test-2</li>
<li>Test-3</li>
</ul>
</nav>
I have the same problem just now and I solve it.
// .tsx
navigationRef.current?.classList.toggle('active');
<div ref={navigationRef} className=' w-[80px] ... duration-500 transition-all ' />
// index.css
#tailwind base;
#tailwind components;
#tailwind utilities;
#layer components {
.active {
width: 300px !important;
}
}
The effect as follow:
No need scale and the effect may be not as expected.

My button loads a page underneath the current page

I have created a button in a html file inside an Angular component. When I click on the button it loads the page underneath the current page and making a single long page, instead of showing a new page. How do I solve this?
<button type="button" class="btn m-1 btn btn-success w-100" (click)="btnClick();"><i class="fa fa-plus"></i>Open page</button>
btnClick= function () {
this.router.navigateByUrl('/testcomponent');
};
<div class="container mt-5">
<div class="row">
<div class="col-sm col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title text-center">OPTIONS</h5>
<p class="card-text">
<button type="button" class="btn m-1 btn btn-success w-100" (click)="btnClick();"><i class="fa fa-plus"></i>Open page</button>
</p>
</div>
</div>
</div>
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { HttpClientModule } from '#angular/common/http';
import { FormsModule } from '#angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { TestComponent} from './testcomponent/testcomponent.component';
import { RouterModule, Routes } from '#angular/router';
const appRoutes: Routes = [
{ path: 'testcomponent', component: TestComponent },
];
#NgModule({
declarations: [
AppComponent,
HeaderComponent,
TestComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
RouterModule.forRoot(
appRoutes,
{ enableTracing: true } // <-- debugging purposes only
)
// other imports here
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
<a [routerLink]="['/testcomponent']">Open page</a> or Open page for more information
please refer this https://angular.io/guide/router