|
| 1 | +**************************************Basics of CSS********************************************** |
| 2 | +> Styling React Components |
| 3 | + 1. CSS Stylesheet Regular css stylesheet |
| 4 | + 2. Inline Styling |
| 5 | + 3. CSS Modules |
| 6 | + 4. CSS in js Libraries (Styled Components) |
| 7 | +> Here we will cover only first three approaches. |
| 8 | + |
| 9 | +1. CSS Stylesheet (Regular css stylesheet) |
| 10 | + > src/Components/Stylesheet.tsx |
| 11 | + > src/myStyle.css |
| 12 | + > CSS file has been imported to the Stylesheet.tsx |
| 13 | + > Stylesheet Component has been calling from the App.tsx |
| 14 | + > Applied primay class without condtions. |
| 15 | + > Applied promary class with props conditionally. props has been passing from the App.tsx |
| 16 | + > If we want to apply multiple class then we have to use the template litterals. |
| 17 | + > <h1 className={`${className} font-xl`}>Multiple Class</h1> |
| 18 | + |
| 19 | +2. Inline Styling |
| 20 | + > Style name should be in camel case version. (Example: fontSize) |
| 21 | + > src/Components/Inline.tsx |
| 22 | + > Inline.tsx component has been used in the App.tsx |
| 23 | + |
| 24 | +3. CSS Modules (Available to react version 2.00 or higher) |
| 25 | + > There are some file naming convenstions for CSS Modules. |
| 26 | + > File name must be suffix with .module.css |
| 27 | + > For example create a two style sheet. |
| 28 | + > src/applyStyle.css (Regular Stylesheet) |
| 29 | + > src/applyStyle.module.css (CSS Modules) |
| 30 | + > Import regular style sheet in App.tsx |
| 31 | + > import '../src/applyStyle.css';; |
| 32 | + > Import CSS Modules style sheet in App.tsx |
| 33 | + > import styles from '../src/applyStyle.module.css'; |
| 34 | + > CSS Modules classes are locally scoped. We can not use the same class in child component. |
| 35 | + This classes are bind with styles attribues, Means we can access the classes after importing the styles attribute. |
| 36 | + > For Example: |
| 37 | + > We have imported applyStyle.css file in parent component (App.tsx). So all the child |
| 38 | + component can access the classes of applyStyle.css |
| 39 | + > Similar we have imported applyStyle.module.css file in parent component (App.tsx). But |
| 40 | + We can not use it's classes in child component, because to use module.css we have to |
| 41 | + import styles attribute then we can access it's classes. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
0 commit comments