Internal Style Sheet-Function Component
import React from 'react'
function CSScomp1() {
const styles={
backgroundColor:'Red',
color:'white',
width:'300px',
height:'300px',
transform:'translate(-50%,-50%)',
position:'absolute',
top:'50%',
left:'50%'
}
return (
<div>
<h1 style={styles} >Internal Stylesheet using CSS</h1>
</div>
)
}
Inline Styles using Function Component
import React from 'react'
function CSScomp1() {
return (
<div>
<h1 style={{
backgroundColor:'Red',
color:'white',
width:'300px',
height:'300px',
transform:'translate(-50%,-50%)',
position:'absolute',
top:'50%',
left:'50%'
}} >Inline Stylesheet using Function Component</h1>
</div>
)
}
export default CSScomp1
External Styles using Function Component
import React from 'react'
import '../CSS/styles.css'
function CSScomp1() {
return (
<div>
<h1 className='main'>External Stylesheet using Function Component</h1>
</div>
)
}
export default CSScomp1
styles.css
.main {
color: blue;
text-align: center;
margin-top: 50px;
font-size: 28px;
border: 2px solid green;
padding: 20px;
background-color: yellow;
}
Internal Style sheet-Class Component
import React from "react";
const styles={
backgroundColor:'Red',
color:'white',
width:'300px',
height:'300px',
transform:'translate(-50%,-50%)',
position:'absolute',
top:'50%',
left:'50%'
}
class Classcomp extends React.Component
{
render(){
return(
<h1 style={styles}>This is Simple Class Component using Internal
CSS</h1>
)
}
}
export default Classcomp
Inline Style sheet using -Class component
import React from "react";
class Classcomp extends React.Component
{
render(){
return(
<h1 style={{
backgroundColor:'green',
color:'white',
width:'300px',
height:'300px',
transform:'translate(-50%,-50%)',
position:'absolute',
top:'50%',
left:'50%'
}}>This is Simple Class Component using Internal CSS</h1>
)
}
}
export default Classcomp
External Style Sheet using Class Component
import React from "react";
import '../CSS/styles.css'
class Classcomp extends React.Component
{
render(){
return(
<h1 className='main'>This is Simple Class Component using External
CSS</h1>
)
}
}
export default Classcomp
styles.css
.main {
color: blue;
text-align: center;
margin-top: 50px;
font-size: 28px;
border: 2px solid green;
padding: 20px;
background-color: yellow;
}