How do i include "css" file in "tsx" and how to use it? i.e how do i render static files?
import * as React from "react";
import { Header } from "./header";
//import "./home.css";
export class Home extends React.Component<{}, {}> {
render() {
return (
<div id="page-top" className="landing-page">
<Header />
</div>
);
}
}
The CSS file is used to describe how HTML elements will be displayed. There are various ways to add CSS file in the HTML document. JavaScript can also be used to load a CSS file in the HTML document.
See this answer:
https://stackoverflow.com/a/37144690/3850405
If you only need css for a class in your component you could do it like below. I like this solution for when inline css does not work and only small changes are needed.
import * as React from "react";
import { Header } from "./header";
export class Home extends React.Component<{}, {}> {
render() {
const css = `
.landing-page {
background-color: orange;
}
`
return (
<div>
<style>
{css}
</style>
<div id="page-top" className="landing-page">
<Header />
</div>
</div>
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With