xxxxxxxxxx
//Multiple inline styles
<div style={{padding:'0px 10px', position: 'fixed'}}>Content</div>
xxxxxxxxxx
// You are actuallty better off using style props
// But you can do it, you have to double brace
// and camel-case the css properties
render() {
return (
<div style={{paddingTop: '2em'}}>
<p>Eh up, me duck!</p>
</div>
)
}
xxxxxxxxxx
render() {
return (
<p style={{color: 'red'}}>
Example Text
</p>
);
}
xxxxxxxxxx
//double brackets, quotations around both key and value in css
<span style={{"font-weight": "750"}}>React Inline Styling </span>
xxxxxxxxxx
// use inline style in react
const myFunction = () => {
return (
<p style={{ fontSize: 24, margin: '0 auto', textAlign: 'center'}}>
Hello world
</p>
);
}
xxxxxxxxxx
function MyComponent(){
2
3return <div style={{ color: 'blue', lineHeight : 10, padding: 20 }}> Inline Styled Component</div>
4
5}
xxxxxxxxxx
// src/App.js
export default function App() {
return (
<main style={{ textAlign: 'center' }}>
<Navbar title="My Special App" />
</main>
);
}
function Navbar({ title }) {
return (
<div style={{ marginTop: '20px' }}>
<h1 style={{ fontWeight: 'bold' }}>{title}</h1>
</div>
)
}